0
空字符串我有一個location
表我用來存儲地理座標:對象與BigDecimals的返回上to_s
class Location < ActiveRecord::Base
# Location has columns/attributes
# BigDecimal latitude
# BigDecimal longitude
(...)
def to_s
@latitude.to_s << ', ' << @longitude.to_s
end
end
然而,當我打電話to_s
上的位置,在BigDecimal
內轉換爲空字符串。
ruby > l
=> #<Location id: 1, latitude: #<BigDecimal:b03edcc,'0.4713577E2',12(12)>, longitude: #<BigDecimal:b03ecb4,'-0.7412786E2',12(12)>, created_at: "2011-08-06 03:41:51", updated_at: "2011-08-06 22:21:48">
ruby > l.latitude
=> #<BigDecimal:b035fb0,'0.4713577E2',12(12)>
ruby > l.latitude.to_s
=> "47.13577"
ruby > l.to_s
=> ", "
任何想法爲什麼?