On 5/17/07, Vasco Andrade e Silva <vascoas / gmail.com> wrote: > MenTaLguY wrote: > > In Ruby's core library, yes. It's possible to implement new methods > > with similar behavior (which is occasionally useful), but that isn't the > > norm. > > > > -mental > > How can i do that? > > I was thinking.. If I want to "bind" self to yield context, with 0 > params, i can use a solution like this one: > > >def create( name, &block ) > > person = Person.new( name ) > > person.instance_eval( &block ) > > p person > >end > > person.instance_eval( &block ) # some kind of yield(self) inside > instance_eval > > but what if i want yield with params, and still have self like > instance_eval? > > Example: > class A > def some_method(&block) > yield(:arg1, :arg2) > end > end > a = A.new > # wanted: self "equals" to a > a.some_method { |arg1, arg2| p self } > > Vasco A. Silva > > -- > Posted via http://www.ruby-forum.com/. > > Now this is really *ugly*, but maybe you can make it less ugly? class A def a &blk blk.call self, 42 end end A.new.a { |o,x| puts "#{self}: #{x}" } A.new.a { |o,x| o.instance_eval{puts "#{self}: #{x}"} } HTH Robert -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw