What is the Ruby equivalent of the "this" function in Java? -


in java there "this" function points method. there equivalent in ruby? instance, there:

def method   this.method end 

the equivalent self. implict. self.first_name same first_name within class unless making assignment.

class book   attr_reader :first_name, :last_name    def full_name      # same self.first_name + ", " + self.last_name     first_name + ", " + last_name   end end 

when making assignment need use self explicitly since ruby has no way of knowing if assigning local variable called first_name or assigning instance.first_name.

class book       def foo     self.first_name = "bar"   end end 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -