Difference between @instance_variable and attr_accessor

前端 未结 6 1840
日久生厌
日久生厌 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:18

    attr_accesor gives you methods to read and write the instance variables. Instance variables are deasigned to be hidden from outside world so to communicate with them we should have attr_ibute accesor methods.

提交回复
热议问题