Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. class Person
  2. def self.example_class_method
  3. puts "We're calling an example class method"
  4. puts "'self is always defined. What is 'self here? Let's see."
  5. p self
  6. puts "That was self!"
  7. end
  8.  
  9. def example_instance_method
  10. puts "We're calling an example *instance* method"
  11. puts "'self' is defined here, too, but it means something different."
  12. p self
  13. puts "That was self, again, but see how it's an instance of the class."
  14. end
  15.  
  16. puts "You'll see this as the class is being defined"
  17. puts "In this context, self is: "
  18. p self
  19. puts "See? self is the Person class"
  20. # this is the end of the class definition
  21. end
  22.  
  23. Person.example_class_method
  24. person = Person.new
  25. person.example_instance_method
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement