From: Paolo Negri Date: 2006-10-04T16:58:05+09:00 Subject: Re: eval confusion Thank you for replying and for the note on 1.9 very interesting! Paolo On 04/10/06, nobu@ruby-lang.org wrote: > Hi, > > At Wed, 4 Oct 2006 08:00:32 +0900, > Paolo Negri wrote in [ruby-talk:217920]: > > #!/bin/ruby > > class DefMethod > > M_COLLECTION = ('a'..'c') > > M_COLLECTION.each do |alpha| > > define_method(alpha) { > > block_given? ? puts(yield(alpha)) : puts(alpha) > > This block_given? sees the context where define_method is > called, that is defining DefMethod and always false. > > > } > > end > > end > > In 1.9, you have to write as: > > > define_method(alpha) {|&block| > > block ? puts(yield(alpha)) : puts(alpha) > > } > > No way in 1.8. > > -- > Nobu Nakada > >