Difference between @instance_variable and attr_accessor

前端 未结 6 1832
日久生厌
日久生厌 2020-12-13 00:28

I Just started learning ruby and I don\'t see the difference between an @instace_variable and an attribute declared using attr_accessor.

Wh

6条回答
  •  一个人的身影
    2020-12-13 01:21

    Because attr_accessor defines methods, you can call them from outside the class. A @variable is only accessible from inside the class.

提交回复
热议问题