Created
February 26, 2012 23:55
-
-
Save rodchile/1919880 to your computer and use it in GitHub Desktop.
Singleton Methods on Ruby
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
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