class Foo
def initialize
@foo = 1
end
end
obj = Foo.new
p obj.instance_variable_get("@foo") # => 1
p obj.instance_variable_get(:@foo) # => 1
p obj.instance_variable_get(:@bar) # => nil
obj = Object.new
p obj.instance_variable_set("@foo", 1) # => 1
p obj.instance_variable_set(:@foo, 2) # => 2
p obj.instance_variable_get(:@foo) # => 2
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |