From: Logan Capaldo Date: 2006-04-09T10:51:43+09:00 Subject: Re: yield, binding On Apr 8, 2006, at 9:40 PM, Gokhan Ersumer wrote: > Hi, > > I'm experimenting with Ruby by writing some kind of DSL. > I wonder if It is possible calling given block to a proc with > different > binding > What I'm trying to achieve is something like this > > class Table > attr_accessor :name, > def getBinding > binding > end > end > > def table > t = Table.new > if block_given? > yield # with t.getBinding > end > t > end > > so I will be able to write (in DSL part) > > table { > name = "FirstTable" > ... > } > > instead of > > table {|t| > t.name = "FirstTable" > ... > } > > Thanks > > Gokhan Ersumer > > -- > Posted via http://www.ruby-forum.com/. > the only way to do this is with eval. def table(s = nil) t = Table.new eval(s, t.getBinding) if s t end table %q{ name = "FirstTable" }