In Ruby, when we say ruby.upcase is telling the object ruby to do the message upcase( the method name ). However, when we say the method puts, Ruby already have the investable object “SELF” which we do not need to put in front of the method puts. So what is “SELF”? Self in Ruby is the default receiver for method calls which always reference the “current object”, and it change depending on where you are. When we puts self in Ruby, it will show the local object reference by self as main, and when we puts self.class into Ruby, it shown self’s Ruby class is an object. So in this case, self is the goest since we do not need to type self into Ruby.
Some people might ask if we ever need self in Ruby then. The answer is yes.
class Software
def self.print_developer
puts “The developer of this software is Jason”
end
end
Software.print_developer
In the context of a class, even self still refers to the current class in this case, which simply become an instance of the class Class now. Defining a method on self creates a class method. *self = Software