From: Srijayanth Sridhar Date: 2009-05-08T18:42:06+09:00 Subject: Re: Understanding { } and block_given --000e0cd2e57cf687dc0469637034 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit This is definitely not a block_given thing. block is coming through as a NilClass it seems. puts block.class yields NilClass. The strange bit is that when I do it outside of instance_eval with just a define_method under irb, it works as expected. I am lost. Anyone? Jayanth On Fri, May 8, 2009 at 11:19 AM, Srijayanth Sridhar wrote: > Hello, > > I have the following: > > class DSL > def DSL.load filename > dsl = new > dsl.instance_eval(File.read(filename)) > dsl > end > def to sym,*args,&block > if block_given? > b=class << self;self;end > b.instance_eval { > define_method(sym,*args,&block) > } > end > end > def method_missing sym,*args > "#{sym}" > end > alias :say puts > end > > foo=DSL.load("sample.dsl") > > > sample.dsl: > > to smile do > say ":)" > end > to be_polite { > say "thank you" > } > smile > be_polite > > > The resulting output is: > > moonwolf@trantor:~/ruby/dsl/todo$ ./dsl.rb > :) > moonwolf@trantor:~/ruby/dsl/todo$ > > be_polite and indeed, anything enclosded in {} doesn't seem to be eval-ed > as > blocks. Why is this? > > Jayanth > --000e0cd2e57cf687dc0469637034--