我们如何实现“就地”转换为散列值的浮点数?动机是不必像这样编写一堆代码
r['delivery_fee'] = r['delivery_fee'].to_f
r['delivery_free_over'] = r['delivery_free_over'].to_f
r['delivery_possible_over'] = r['delivery_possible_over'].to_f
r['delivery_range'] = r['delivery_range'].to_f
反而
to_f r['delivery_fee']
to_f r['delivery_free_over']
# ...
我这样做了,但它没有按预期的方式工作。
def to_f(s)
s = s.to_f
end
data = "1"
p data # => "1"
to_f data
p data # => Still "1" and not float