Ryan Davis wrote:
> On Feb 18, 2010, at 11:57 , Glenn Ritz wrote:
> 
>> Hi,
>> 
>> I would like to add self to an Enumerable object in Ruby 1.9, like in
>> this (admittedly) contrived example:
>> 
>> %w(cat dog mouse).each.with_self { |e, s| puts "self: #{s.inspect}, e: #{e}" }
> 
> IDGI. What's the point?
> 
> %w(cat dog mouse).each { |e| s = self; puts "self: #{s.inspect}, e: 
> #{e}" }
> 
> or better:
> 
> %w(cat dog mouse).each { |e| puts "self: #{self.inspect}, e: #{e}" }


I want to be able to refer to the array receiver inside of the block. 
In this code:

%w(cat dog mouse).each { |e| s = self; puts "self: #{s.inspect}, e: 
#{e}" }

self is main (or whatever class you execute the code in), not the array.

-- 
Posted via http://www.ruby-forum.com/.