Created
November 2, 2010 11:28
-
-
Save cheeyeo/659505 to your computer and use it in GitHub Desktop.
Example of using Ruby's built in Singleton Module
This file contains hidden or 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
require 'singleton' | |
class MyClass | |
attr_accessor :data | |
include Singleton | |
end | |
a = MyClass.instance | |
b = MyClass.instance | |
#both a and b point to the same object | |
a.data=123 | |
p b.data #also prints out 123 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment