On 23/07/05, Gene Tani <gene.tani / gmail.com> wrote:
> myhash['keyval'] ||= newval  ## won't stomp on existing value if
> 'keyval' already in my #keys
>

Though beware of nil and false

irb(main):001:0> h = {1 => nil, 2 => false, 3 => true}
=> {1=>nil, 2=>false, 3=>true}
irb(main):002:0> h[1] ||= 2
=> 2
irb(main):003:0> h[2] ||= 3
=> 3
irb(main):004:0> h[4] ||= 5
=> 5
irb(main):005:0> h
=> {1=>2, 2=>3, 3=>true, 4=>5}

regards,

Brian

 
> also, Hash#merge and Hash#merge! take blocks to say how to handle
> duplicated key values
> 
> 
>


-- 
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/