Guest User

about_hashes

a guest
Jul 12th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.44 KB | None | 0 0
  1. # From ruby koans (http://rubykoans.com) - specifically about_hashes.rb
  2. # Specifically def test_default_value_is_the_same_object
  3. # Line 93
  4. # This would be how I would run it in irb
  5.  
  6. hash = Hash.new([])
  7. hash[:one] << "uno"
  8. hash[:two] << "dos"
  9. hash[:one] # => ["uno", "dos"]
  10. hash[:two] # => ["uno", "dos"]
  11. hash[:three] # => ["uno", "dos"]
  12.  
  13. newHash = Hash.new
  14. newHash[:one] << "uno" # NoMethodError : undefined method '<<' for nil:NilClass
Advertisement
Add Comment
Please, Sign In to add comment