如下面的代码所示,分配h ['1']会影响对象。谁能解释这是怎么发生的?
class Post
attr_accessor :json_data, :first_name
def initialize
@json_data = {'2': 'two'}
@first_name = 'check'
end
end
p1 = Post.new
h = p1.json_data
h['1'] = 'one'
p p1
O / P:@json_data = {:“ 2” =>“两个”,“ 1” =>“一个”},@ first_name =“ jhvhvvjh”