从课堂上读常量

山姆
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值的正确语法是什么?谢谢你。

Dty

这可能就是你想要的

p Employee::EMP

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章