0
나는 지리적 좌표를 저장하는 데 사용하는 location
테이블이 있습니다.BigDecimals를 사용하는 Object가 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
=> ", "
왜 그런가?