From: Ross Bamford Date: 2006-05-02T08:56:00+09:00 Subject: Re: from block to code (also: how to get the bindings of a block) On Tue, 2006-05-02 at 05:11 +0900, 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. > > > 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) In return for keeping the equals signs, would the users let you get away with a few 'at' symbols? def recipe(name, &blk) o = Object.new o.instance_eval(&blk) o.instance_variables.inject({}) do |h,s| h[s[1..-1]] = o.instance_variable_get(s) h end end # => nil recipe "eggs and bacon" do @eggs = [2,:big] @bacon = 3 end # => {"bacon"=>3, "eggs"=>[2, :big]} (Though I'd really recommend most of the other ideas from this thread over this). -- Ross Bamford - rosco@roscopeco.REMOVE.co.uk