Skip to content

Instantly share code, notes, and snippets.

@cheeyeo
Created November 2, 2010 11:28
Show Gist options
  • Save cheeyeo/659505 to your computer and use it in GitHub Desktop.
Save cheeyeo/659505 to your computer and use it in GitHub Desktop.
Example of using Ruby's built in Singleton Module
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