1. attr_accessor的用法相当简单, 就相当于getter和setter,看一个类就知道怎样用了: Ruby代码 class Test attr_accessor :name def initialize() @name = "yanzilee9292" end end #test puts Test.n
attr_reader 及attr_accessor主要是用来设置或读取类中的属性值.具体用法: class Hello attr_reader :msg def initialize @msg = "Hello, World" end def test print @msg end end h = H