Last active
August 29, 2015 14:01
-
-
Save brandonrich/759841e5a9f67d663a84 to your computer and use it in GitHub Desktop.
behavior of class <<
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
a's values: | |
value of Foo.name: bar | |
Foo's object ID: 70207511032180 | |
self's object ID: 70207511031980 | |
b's values: | |
value of Foo.name: bar | |
Foo's object ID: 70207511032180 | |
self's object ID: 70207511031940 | |
# Foo is the same instance everywhere across multiple instances |
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
class Thing | |
module Foo | |
class << self | |
attr_accessor :name | |
end | |
end | |
def setFoo(val) | |
Foo.name = val | |
end | |
def doSomething | |
puts "value of Foo.name: " + Foo.name | |
puts "Foo's object ID: " + Foo.object_id.to_s | |
puts "self's object ID: " + self.object_id.to_s | |
end | |
end | |
a = Thing.new | |
a.setFoo("bar") | |
b = Thing.new | |
puts "a's values:" | |
a.doSomething | |
puts "\nb's values:" | |
b.doSomething | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment