Class: VectorNumber::SpecialUnit
- Inherits:
-
Object
- Object
- VectorNumber::SpecialUnit
- Defined in:
- lib/vector_number/special_unit.rb
Overview
Class for representing special (unique) units.
There usually isn’t much point in using these, aside from NUMERIC_UNITS. However, they can be helpful to denote units that aren’t equal to any other object.
VectorNumber#to_s (and inspect) will use #to_s text instead of #inspect text for these units by default, without a multiplication operator. However, consider using customization of VectorNumber#to_s instead if this is what you want.
Instance Method Summary collapse
-
#initialize(unit, text = unit.to_s) ⇒ SpecialUnit
constructor
Returns a new, unique unit, not equal to any other unit.
-
#inspect ⇒ String
Get string representation of the unit for debugging.
-
#pretty_print(pp) ⇒ void
Support for PP, outputs the same text as #inspect.
-
#to_s ⇒ String
Get predefined string representation of the unit.
Constructor Details
#initialize(unit, text = unit.to_s) ⇒ SpecialUnit
Returns a new, unique unit, not equal to any other unit.
19 20 21 22 |
# File 'lib/vector_number/special_unit.rb', line 19 def initialize(unit, text = unit.to_s) @unit = unit @text = text end |
Instance Method Details
#inspect ⇒ String
Get string representation of the unit for debugging.
44 45 46 |
# File 'lib/vector_number/special_unit.rb', line 44 def inspect "unit/#{@unit}" end |
#pretty_print(pp) ⇒ void
This method returns an undefined value.
Support for PP, outputs the same text as #inspect.
37 38 39 |
# File 'lib/vector_number/special_unit.rb', line 37 def pretty_print(pp) pp.text(inspect) end |
#to_s ⇒ String
Get predefined string representation of the unit.
27 28 29 |
# File 'lib/vector_number/special_unit.rb', line 27 def to_s @text end |