attr vs attr_accessor

后端 未结 3 1338
无人及你
无人及你 2020-12-15 05:31

In Ruby there are four different getter and setter methods for instance variables, attr, attr_reader, attr_writer, and attr_acce

3条回答
  •  心在旅途
    2020-12-15 06:06

    In Ruby 1.8, attr can define only a single attribute, with an optional true to create a setter . In 1.9 it behaves like attr_reader:it allows for multiple attributes. As @Linuxios says, the optional boolean is deprecated.

提交回复
热议问题