Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated inspect methods for dimension and unit

  • Loading branch information...
commit 858d7803248a0971984403600e214e78506e95cd 1 parent 8a5213e
@bhuga authored
Showing with 18 additions and 6 deletions.
  1. +1 −1  lib/quantity/dimension.rb
  2. +17 −5 lib/quantity/unit.rb
View
2  lib/quantity/dimension.rb
@@ -185,7 +185,7 @@ def <=>(other)
#
# @return [String]
def inspect
- sprintf("#<%s:%#0x %s (%s)>", self.class.name, object_id, string_form, @name)
+ sprintf("#<%s:0x%s @name=%s reduced_name=%s>", self.class.name, self.__id__.to_s(16), @name, reduced_name)
end
View
22 lib/quantity/unit.rb
@@ -76,6 +76,12 @@ def self.add_units(&block)
self.class_eval(&block)
end
+ # Reset the world. Useful in testing.
+ # @private
+ def self.__reset!
+ @@units = {}
+ end
+
### Instance-level methods/vars
attr_reader :name, :value, :dimension, :aliases
@@ -85,6 +91,11 @@ def names
[@name] + @aliases
end
+ # A reduced form of this unit
+ def reduced_name
+ to_string_form.to_sym
+ end
+
# Can this unit be converted into the target unit?
# @param [Symbol String Unit]
# @return [Boolean]
@@ -150,7 +161,8 @@ def s_for(value)
end
def inspect
- "<Unit #{@name} (#{@object_id}), value #{@value}, dimension #{@dimension}>"
+ sprintf('#<%s:0x%s @name=%s @value=%s @dimension=%s>', self.class.name,
+ self.__id__.to_s(16), @name.inspect, @value.inspect, @dimension.inspect)
end
def <=>(other)
@@ -311,10 +323,10 @@ def self.string_form(dimension,units)
string
end
- # Reset the world. Useful in testing.
- # @private
- def self.__reset!
- @@units = {}
+ # A reduced form of this unit
+ def reduced_name
+ string_form.to_sym
end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.