Created
May 3, 2016 16:10
-
-
Save GrahamSM/395a2175d0252cd81c79a3ad39dc75fe to your computer and use it in GitHub Desktop.
Revisions
-
GrahamSM created this gist
May 3, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ There are two distinct cases that I will refer to in order to explain the behaviour of 'self' in ruby First is within class 'instances'. When self is called within a class instance (instance of an object of said class), self is in this case referring to that particular instance. For example: def my_method p self end my_object = Object_Class.new my_object.my_method In the above example, my_method would print the object my_object to the console. Case two is outside the scope of an class instance. In this situation, self is referring to the class itself. For example, if we were to reference self inside of a class method (method prefixed by self), or outside the scope of any method definitions, we would be referencing the class itself.