Created
November 20, 2009 20:27
-
-
Save tonini/239749 to your computer and use it in GitHub Desktop.
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
# singleton_class.rb | |
# zastav [@samueltonini] | |
obj = Object.new | |
def obj.who_i_am? | |
puts "I'm a singleton method" | |
end | |
singleton_class = class << obj | |
def and_who_i_am? | |
puts "I'm a singleton method defined in a singleton class or also called eigenclass" | |
end | |
def bye | |
puts "bye dude!" | |
end | |
self # singleton class object | |
end | |
obj.who_i_am? # I'm a singleton method | |
obj.and_who_i_am? # I'm a singleton method defined in a singleton class or also called eigenclass | |
obj.bye # bye dude! | |
p singleton_class.instance_methods(false) # [:who_i_am?, :and_who_i_am?, :bye] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment