Skip to content

Instantly share code, notes, and snippets.

@brandonrich
Last active August 29, 2015 14:01
Show Gist options
  • Save brandonrich/759841e5a9f67d663a84 to your computer and use it in GitHub Desktop.
Save brandonrich/759841e5a9f67d663a84 to your computer and use it in GitHub Desktop.
behavior of class <<
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
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