I m getting a response in the format of
#<Response:0x000... @first = "Charlie", @last=Kelly, ....
并且我需要把这变成一个 has(积极的商人)。 目前,我正在经历各种变量,并这样做:
response.instance_variables.each do |r|
my_hash.merge!(r.to_s.delete("@").intern => response.instance_eval(r.to_s.delete("@")))
end
This works, it will produce {:first = "charlie", :last => "kelly"}
, but it seems a bit hacky and unstable. Is there a better way to do this ?
edit:我刚刚认识到,我可以在这个方程式的第二部分使用“可变的”植被,但这仍然留下主要问题。