Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道我x.to_s的不起作用,我需要使用.send(something),但我无法正确使用语法。如果您能告诉我正确的发送语法,我将不胜感激。
x.to_s
.send(something)
h = Hash.new @cars.each do|x| h["x.to_s"] = 0 end
如果您打算将字符串表示形式x用作哈希键,请删除引号:
x
h[x.to_s] = 0
我猜你会发现这个:
h = Hash.new @cars.each 做|x| h[x.send(:to_s)] = 0 结尾
我真的不明白为什么你需要send在这里使用。简单的有什么问题:
send
Hash[@cars.map(&:to_s).zip([0].cycle)]