Skip to content

Instantly share code, notes, and snippets.

@shunchu
Last active December 20, 2015 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shunchu/6047582 to your computer and use it in GitHub Desktop.
Save shunchu/6047582 to your computer and use it in GitHub Desktop.
Ways to create Singleton Methods in Ruby
# Reference: http://madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html
class Dog
def self.closest_relative
"wolf"
end
end
class Dog
class << self
def closest_relative
"wolf"
end
end
end
def Dog.closest_relative
"wolf"
end
class << Dog
def closest_relative
"wolf"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment