Skip to content

Instantly share code, notes, and snippets.

@rodchile
Created February 26, 2012 23:55
Show Gist options
  • Save rodchile/1919880 to your computer and use it in GitHub Desktop.
Save rodchile/1919880 to your computer and use it in GitHub Desktop.
Singleton Methods on Ruby
myObject = Object.new
def myObject.sayHello
puts 'Hello from my singleton method! This is me: '
puts self
end
myObject.sayHello
puts "Any doubts? I'm still the same object:"
puts myObject
## And the terminal response is:
=begin
Hello from my singleton method! This is me:
#<Object:0x103f3e478>
Any doubts? I'm still the same object:
#<Object:0x103f3e478>
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment