Skip to content

Instantly share code, notes, and snippets.

@zzak
Created October 23, 2012 22:16
Show Gist options
  • Save zzak/3942017 to your computer and use it in GitHub Desktop.
Save zzak/3942017 to your computer and use it in GitHub Desktop.
1.9.3p286 :001 > class MyClass
1.9.3p286 :002?> attr_accessor :name
1.9.3p286 :003?> end
=> nil
1.9.3p286 :004 > hash = {}
=> {}
1.9.3p286 :005 > me = MyClass.new
=> #<MyClass:0x00000001f83bc0>
1.9.3p286 :006 > hash.store me.to_s, me
=> #<MyClass:0x00000001f83bc0>
1.9.3p286 :007 > hash.each_pair {|k,v| puts "#{k}'s name is #{v.name}"}
#<MyClass:0x00000001f83bc0>'s name is
=> {"#<MyClass:0x00000001f83bc0>"=>#<MyClass:0x00000001f83bc0>}
1.9.3p286 :008 > me.name = 'zak'
=> "zak"
1.9.3p286 :010 > hash.each_pair {|k,v| puts "#{k}'s name is #{v.name}"}
#<MyClass:0x00000001f83bc0>'s name is zak
=> {"#<MyClass:0x00000001f83bc0>"=>#<MyClass:0x00000001f83bc0 @name="zak">}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment