Skip to content

Instantly share code, notes, and snippets.

@astopo
Created July 14, 2014 20:14
Show Gist options
  • Save astopo/fe11169d88f2f157d7a4 to your computer and use it in GitHub Desktop.
Save astopo/fe11169d88f2f157d7a4 to your computer and use it in GitHub Desktop.
self in Ruby

The self keyword allows for access to the current object.

When you call a method on an object, such as object.method, the object receives a method message. The object will respond to the method if there is a method defined for it. Inside that method, you have access to the object via the keyword self.

When you call a method without an explicit receiving object, it just calls it on self.

If you are inside an instance method but need access to a class method, you would use self.class.method_you_want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment