Skip to content

Instantly share code, notes, and snippets.

@ngpestelos
Created September 29, 2013 03:34
Show Gist options
  • Save ngpestelos/6749124 to your computer and use it in GitHub Desktop.
Save ngpestelos/6749124 to your computer and use it in GitHub Desktop.
singleton methods in Ruby
# see Metaprogramming Ruby, p. 101
str = "just a regular string"
def str.title?
self.upcase == self
end
str.title? # false
str.methods.grep(/title?/) # ["title?"]
str.singleton_methods # ["title?"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment