On Tue, May 13, 2008 at 12:04 PM, Sebastian Hungerecker <sepp2k / googlemail.com> wrote: > Paul Dugdale wrote: > > What I was trying to find out is - is there any way of passing a > > reference to the value to the 'each' block, rather than a copy of the > > value. > > Without having to refer to the hash again in the block like this: > > hash.each { |k,v| hash[k] = my_value } > > If your v object is immutable, you'll have to do the above, I'm afraid. Even if it isn't not doing so can be problematic: a = "Fred" h = {:flintstone => a} a # => "Fred" h # => {:flintstone=>"Fred"} h.each {|k,v| v.downcase!} h # => {:flintstone=>"fred"} # Expected, but... a # => "fred" # Expected????!!!! Understanding how object reference differs from pointer reference and value semantics is crucial to starting to understand a pure object language like Ruby. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/