Created
October 23, 2012 22:16
-
-
Save zzak/3942017 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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