code_junkie

Hashes of Hashes Idiom in Ruby?

Nov 11th, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. h = Hash.new
  2. h['x'] = Hash.new if not h.key?('x')
  3. h['x']['y'] = value_to_insert
  4.  
  5. h = Hash.new
  6. h['x']['y'] = value_to_insert
  7.  
  8. looked_up_value = h['w']['z']
  9.  
  10. h = Hash.new { |h, k| h[k] = Hash.new }
  11.  
  12. hash = Hash.new(&(p=lambda{|h,k| h[k] = Hash.new(&p)}))
  13.  
  14. ((h ||= { })['w'] ||= { })['z']
Add Comment
Please, Sign In to add comment