class Employee
EMP = []
attr_reader :name, :hobbies, :friends
def initialize(name)
@name = name
@hobbies = []
@friends = []
EMP << self
end
end
em = Employee.new("Joe")
em2 = Employee.new("Blake")
如果我尝试:p em2.EMP
否则p em2.EMP[1]
我得到
“#的undef meth EMP
如果我尝试 p Employee.EMP
我收到“ Person:Class ...的undef meth EMP”
获得EMP值的正确语法是什么?谢谢你。
这可能就是你想要的
p Employee::EMP
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句