Displaying 1 result from an estimated 1 matches for "valid_unit".
Did you mean:
valid_units
2006 Mar 03
0
unused composed_of bits
...ttle bit of my temperature class:
class Temperature
# Composed of a float with 1 sig fig and units of Celsius, Fahrenheit or Kelvin
# Implements to_s, to_html and a number of conversions and bang conversions
attr_reader :temp, :units
def initialize( temperature, units = "F" )
unless valid_units?(units)
units = "F"
end
@temp = temperature = ((10 * temperature).to_f.round)/10.0
@units = units.upcase
end
def to_c
convert_to("C")
end
... etc.
So in my app model:
class Profile < ActiveRecord::Base
composed_of :temperature, :class_name => Temper...