Ruby-在initialize方法的内部和外部声明实例变量

时间:2018-11-13 21:55:34

标签: ruby class initialization instance-variables

在Ruby中,在构造函数/ initialize方法内部声明实例变量与在外部声明实例变量之间有什么区别?例如:

class Pet
    @ age = 1    # outside initilize

    def initialize (name, breed)
        @name = name
        @breed = breed
        @age = 1    # inside intilize, is this different than above?
    end
end

0 个答案:

没有答案