有什麼辦法可以做到這一點嗎?Ruby:使用Object.send來分配變量
a = Struct.new(:c).new(1)
b = Struct.new(:c).new(2)
a.send(:c)
=> 1
b.send(:c)
=> 2
a.send(:c) = b.send(:c)
最後一行導致錯誤:
syntax error, unexpected '=', expecting $end
a.send(:c) = b.send(:c)
^
你的意思是'bar ='。 – Adrian 2010-07-02 18:00:10
@阿德里安:是的,我做到了。謝謝。 – sepp2k 2010-07-02 18:01:32