On 02/18/2010 10:39 PM, Glenn Ritz wrote: > 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. What is the point of that? I mean, you can *always* have a reference to the instance around. s = %w(cat dog mouse) s.each {|e| ...} Or, in 1.9 %w(cat dog mouse).tap {|s| s.each {|e| ...}} Even if you pass around a block for later usage with #each you can make sure the collection is accessible inside the block. What is the real use case of this? Passing the collection into the block during iteration feels wrong. For example, typically when iterating modifications of the underlying collection are dangerous. Why do you need this feature? Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/