Skip to content

Instantly share code, notes, and snippets.

@irridescentrambler
Last active September 27, 2019 10:51
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 irridescentrambler/b84481904b31fce8369989ca1f2dec1b to your computer and use it in GitHub Desktop.
Save irridescentrambler/b84481904b31fce8369989ca1f2dec1b to your computer and use it in GitHub Desktop.
# A simple class in Ruby
class Human
def introduce
"Hi, I am a #{self.class.name}"
end
end
Human.ancestors
#=> [Human, Object, Kernel, BasicObject]
# Object is present in Human class's ancestor tree.
# Hence #method of Object can be used on instances of Human class
Human.new.method(:introduce)
#=> #<Method: Human#introduce>
# Method object for Human's instance method #introduce
method(:puts)
#=> #<Method: main.puts>
# Method object for #puts method.
[1,2,3,4].method(:length)
#=> #<Method: Array#length>
# Method object for Array's instance method #length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment