Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8118033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:21:24+00:00 2026-06-06T04:21:24+00:00

I have a DSL – like piece of Ruby code that looks like this:

  • 0

I have a DSL – like piece of Ruby code that looks like this:

Activity.new('20-06-2012') do
  Eat.log do |l|
    l.duration = 0.30
    l.priority = 5
  end
  Work.log do |l|
    l.duration = 2
    l.priority = 3
  end
end

Every time the log() method is called, a Log object is instantiated (behind the scenes) with the block passed to the method (the block is passed on to the Log object’s constructor). My question is, is there a way to collect all the returns from the log() method? In the example above, the return value of the outermost block is the last call to log(). But I want to get all the calls’ results in an array, not just the last one.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:21:26+00:00Added an answer on June 6, 2026 at 4:21 am

    Your internal DSL is still too Ruby-like, you may refactor it to look something like this:

    activity '20-06-2012' do
      log :eat do
        duration 0.30
        priority 5
      end
      log :work do
        duration 2
        priority 3
      end
    end
    

    Now capture the calls in your instance_eval and accumulate the values in an internal array, the usual DSL stuff.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Camel Route Definition written in Java DSL like this: from(myEndpoint) .throttle(200)
I have a groovy DSL script like this: entity(attribute1:one, attribute2:two) so far so good.
I have a relatively simple DSL that I would like to handle more robustly
I have this code for on ASP.NET MVC website: x.For<AccountController>().TheDefault.Is.ConstructedBy(() => new AccountController()); This
I have a DSL Java object, i.e. a POJO which returns this in setters
I have defined a small DSL that is mostly written in the form of
I have an option parsing gem that provides a DSL for creating commands. In
I have lately been delving into F# and the new DSL stuff as in
OK, so things have progressed significantly with my DSL since I asked this question
There's a new dsl in capybara 1.0.0.rc1 that's very similar to steak. I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.