Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. # A simple class in Ruby
  2. class Human
  3. def introduce
  4. "Hi, I am a #{self.class.name}"
  5. end
  6. end
  7.  
  8. Human.ancestors
  9. #=> [Human, Object, Kernel, BasicObject]
  10. # Object is present in Human class's ancestor tree.
  11.  
  12. method(:puts)
  13. #=> #<Method: main.puts>
  14. # Method object for #puts method.
  15.  
  16. [1,2,3,4].method(:length)
  17. #=> #<Method: Array#length>
  18. # Method object for Array's instance method #length
  19.  
  20. Human.new.method(:introduce)
  21. #=> #<Method: Human#introduce>
  22. # Method object for Human's instance method #introduce
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement