lib/quantify/unit/base_unit.rb in quantify-2.0.0 vs lib/quantify/unit/base_unit.rb in quantify-2.0.1
- old
+ new
@@ -1,6 +1,5 @@
-
module Quantify
module Unit
class Base
extend ExtendedMethods
@@ -58,12 +57,12 @@
# load :name => 'hectare', :physical_quantity => :area, :factor => 10000
# load :name => :watt, :physical_quantity => :power, :symbol => 'W'
#
# end
#
- def self.configure &block
- class_eval &block if block
+ def self.configure(&block)
+ class_eval(&block) if block
end
attr_reader :name, :symbol, :label, :factor, :dimensions
attr_reader :acts_as_alternative_unit, :acts_as_equivalent_unit
@@ -400,11 +399,11 @@
# are returned within the array
#
def alternatives(by=nil)
@dimensions.units(nil).reject do |unit|
unit.is_equivalent_to?(self) || !unit.acts_as_alternative_unit
- end.map(&by)
+ end.map(&by).to_a
end
# Returns the SI unit for the same physical quantity which is represented
# by self, e.g.
#
@@ -447,12 +446,12 @@
# Unit.m.valid_prefixes :symbol #=> [ "da", "h", "k", "M", "G",
# "T", "P" ... ]
#
def valid_prefixes(by=nil)
return [] if is_compound_unit? && has_multiple_base_units?
- return Unit::Prefix.si_prefixes.map(&by) if is_si_unit?
- return Unit::Prefix.non_si_prefixes.map(&by) if is_non_si_unit?
+ return Unit::Prefix.si_prefixes.map(&by).to_a if is_si_unit?
+ return Unit::Prefix.non_si_prefixes.map(&by).to_a if is_non_si_unit?
end
# Multiply two units together. This results in the generation of a compound
# unit.
#
@@ -535,10 +534,10 @@
# each instance variable)
#
def to_hash
hash = {}
self.instance_variables.each do |var|
- symbol = var.gsub("@","").to_sym
+ symbol = var.to_s.gsub("@","").to_sym
hash[symbol] = send symbol
end
return hash
end