class Sample
attr_accessor :x,:y
def initialize
@x = "x"
y = "y"
end
end
Sample.new.instance_variables => [:@x]
class Sample
attr_accessor :x,:y
def initialize
@x = "x"
self.y = "y"
end
end
Sample.new.instance_variables => [:@x, :@y]
谁能让我知道这里发生了什么。为什么 y 第二次是 instance_variable?