Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. Self is a keyword in Ruby that refers to the *current object* when it is called. However, the current object can vary depending on where the self keyword is inside a ruby program.
  2.  
  3. Inside class definitions, the self keyword refers to the *class itself*. This is why methods defined in the self.method_name format are class methods and not instance methods.
  4.  
  5. Inside instance method definitions, the self keyword refers to the instance of the class which is calling that method. So for example if we had a Car class with some instance method that puts out "self", running that method on any Car instance would return the actual instance of the Car itself.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement