Created
August 12, 2013 18:56
-
-
Save klustig88/6213908 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
def self.example_class_method | |
puts "We're calling an example class method" | |
puts "'self' is always defined. What is 'self' here? Let's see." | |
p self | |
puts "That was self!" | |
end | |
def example_instance_method | |
puts "We're calling an example *instance* method" | |
puts "'self' is defined here, too, but it means something different." | |
p self | |
puts "That was self, again, but see how it's an instance of the class." | |
end | |
end | |
Person.example_class_method | |
luis = Person.new | |
luis.example_instance_method | |
# When Self is called within a class method, self literraly refers to the class it is being called from. | |
# When self is called within an instance method, self refers to the instance created within the class. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment