Class: Stick::Units::BaseUnit
- Inherits:
-
Object
- Object
- Stick::Units::BaseUnit
- Defined in:
- lib/stick/units/base.rb
Instance Attribute Summary collapse
-
#converter ⇒ Object
readonly
Returns the value of attribute converter.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #conversion ⇒ Object
- #hash ⇒ Object
-
#initialize(name, converter = Units::Converter.current) ⇒ BaseUnit
constructor
A new instance of BaseUnit.
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(name, converter = Units::Converter.current) ⇒ BaseUnit
Returns a new instance of BaseUnit.
142 143 144 145 146 147 |
# File 'lib/stick/units/base.rb', line 142 def initialize(name, converter = Units::Converter.current) name = name.to_sym raise ::ArgumentError, "unit #{name.to_s.dump} not registered with #{converter}" if not converter.registered? name @name = name @converter = converter end |
Instance Attribute Details
#converter ⇒ Object (readonly)
Returns the value of attribute converter.
140 141 142 |
# File 'lib/stick/units/base.rb', line 140 def converter @converter end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
140 141 142 |
# File 'lib/stick/units/base.rb', line 140 def name @name end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
153 154 155 |
# File 'lib/stick/units/base.rb', line 153 def ==(other) other.is_a?(Units::BaseUnit) && other.name == @name && other.converter == @converter end |
#conversion ⇒ Object
149 150 151 |
# File 'lib/stick/units/base.rb', line 149 def conversion @converter.send(:conversions, @name) end |
#hash ⇒ Object
159 160 161 |
# File 'lib/stick/units/base.rb', line 159 def hash @name.hash ^ @converter.hash end |