Skip to content

Commit

Permalink
Updated inspect methods for dimension and unit
Browse files Browse the repository at this point in the history
  • Loading branch information
bhuga committed Jan 17, 2010
1 parent 8a5213e commit 858d780
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/quantity/dimension.rb
Expand Up @@ -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


Expand Down
22 changes: 17 additions & 5 deletions lib/quantity/unit.rb
Expand Up @@ -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

Expand All @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 858d780

Please sign in to comment.