From: ara.t.howard@... Date: 2006-05-02T06:30:46+09:00 Subject: Re: from block to code (also: how to get the bindings of a block) On Tue, 2 May 2006, chiaro scuro wrote: > On 5/1/06, Jacob Fugal wrote: >> >> On 5/1/06, chiaro scuro wrote: >> > I need to keep the equal signs. >> >> This is my big question; why do you need the equal signs? I see >> nothing inherent about the "recipe" domain that makes the equal signs >> necessary or even desirable. If you were willing to ditch them, a >> whole slew of simpler and cleaner implementations are available. >> >> Jacob Fugal >> >> > I realize that would make it much easier in ruby. > It's just that the equal signs make lots of sense to my DSL users. (forget > the recipes, it's just an example) > > Look, it's not a matter of life or death. *of course* I can do without if > there is no alternative. > (eventually I did find a solution to this -although it's a cheesy one- but I > am not saying yet ;-) > > It just bothers me that I cannot access that context if I need to, and in > this case I do. it would be tough to convince me that people wouldn't find this syntax natural: harp:~ > cat a.rb class Recipe < Hash attr 'name' def initialize name, &b @name = name instance_eval &b end def method_missing m, *a, &b m = m.to_s.delete '=' self[m] = a.size > 1 ? a : a.shift end end def recipe(*a, &b) Recipe.new(*a, &b) end r = recipe "breakfast" do eggs 2, :big bacon 3 end p r harp:~ > ruby a.rb {"bacon"=>3, "eggs"=>[2, :big]} for example, write down a recipe and see if you use the '=' sign ;-) regards. -a -- be kind whenever possible... it is always possible. - h.h. the 14th dali lama