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]
我得到了
“unf meth EMP for#
如果我试试
p Employee.EMP
我得到“针对人的未定义的EMP:Class ...”
获取EMP值的正确语法是什么? 谢谢。
答案 0 :(得分:1)
您需要使用Employee::EMP
。
答案 1 :(得分:1)
这可能是你想要的
p Employee::EMP