lib/ruby-units.rb in ruby-units-0.3.5 vs lib/ruby-units.rb in ruby-units-0.3.6

- old
+ new

@@ -1,10 +1,10 @@ require 'mathn' require 'rational' require 'date' require 'parsedate' -# = Ruby Units 0.3.5 +# = Ruby Units 0.3.6 # # Copyright 2006 by Kevin C. Olbrich, Ph.D. # # See http://rubyforge.org/ruby-units/ # @@ -38,11 +38,11 @@ # end # Unit.setup class Unit < Numeric require 'units' # pre-generate hashes from unit definitions for performance. - VERSION = '0.3.5' + VERSION = '0.3.6' @@USER_DEFINITIONS = {} @@PREFIX_VALUES = {} @@PREFIX_MAP = {} @@UNIT_MAP = {} @@UNIT_VALUES = {} @@ -686,23 +686,26 @@ return out end # negates the scalar of the Unit def -@ + return -@scalar if self.unitless? Unit.new(-@scalar,@numerator,@denominator) end # returns abs of scalar, without the units def abs return @scalar.abs end def ceil + return @scalar.ceil if self.unitless? Unit.new(@scalar.ceil, @numerator, @denominator) end def floor + return @scalar.floor if self.unitless? Unit.new(@scalar.floor, @numerator, @denominator) end # if unitless, returns an int def to_int @@ -716,17 +719,19 @@ end alias :time :to_time alias :to_i :to_int def truncate + return @scalar.truncate if self.unitless? Unit.new(@scalar.truncate, @numerator, @denominator) end def to_datetime DateTime.new(self.to('d').scalar) end def round + return @scalar.round if self.unitless? Unit.new(@scalar.round, @numerator, @denominator) end # true if scalar is zero def zero?