In Ruby there are four different getter and setter methods for instance variables, attr
, attr_reader
, attr_writer
, and attr_accessor
. The question is, is in Ruby attr :dilithium
, the same as attr_reader :dilithium
, and identical to attr_accessor :dilithium
if an additional parameter true is passed? That is to say is
class Enterprise
attr :dilithium, true
identical to
class Enterprise
attr_accessor :dilithium
Are the two functions attr
and attr_accessor
more or less redundant?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…