Ruby method like `self` that refers to instance

前端 未结 5 415
迷失自我
迷失自我 2021-02-02 13:50

Is there a method in Ruby that refers to the current instance of a class, in the way that self refers to the class itself?

5条回答
  •  旧巷少年郎
    2021-02-02 14:01

    Within an instance method of a class self refers to that instance. To get the class within an instance you can call self.class. If you call self within a class method, you get the class. Inside a class method you can't access any instance of the class.

提交回复
热议问题