From: Joel VanderWerf Date: 2008-10-08T03:11:12+09:00 Subject: [ruby-core:19177] Re: [Feature #615] "with" operator Pit Capitain wrote: > Maybe I see it too simplistically, but if all that's wanted in this > discussion is a possibility to get access to the outer scope, then all > you have to do is to capture it in a local variable: > > def with( obj, &blk ) > obj.instance_eval( &blk ) > end > > outer_self = self > with "sample" do > puts "inner self: #{self.class} #{self}" > puts "outer self: #{outer_self.class} #{outer_self}" > end > > which results in > > inner self: String sample > outer self: Object main and in 1.9: def with( obj, &blk ) obj.instance_exec( self, &blk ) end with "sample" do |outer_self| puts "inner self: #{self.class} #{self}" puts "outer self: #{outer_self.class} #{outer_self}" end -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407