Module: RubyUnits::String
- Included in:
- String
- Defined in:
- lib/ruby_units/string.rb
Overview
Extra methods for converting [String] objects to [RubyUnits::Unit] objects and using string formatting with Units.
Instance Method Summary collapse
-
#%(*other) ⇒ String
Format unit output using formatting codes.
- #convert_to(other) ⇒ Unit
-
#to_unit(other = nil) ⇒ RubyUnits::Unit
Make a string into a unit.
Instance Method Details
#%(*other) ⇒ String
Format unit output using formatting codes
22 23 24 25 26 27 28 |
# File 'lib/ruby_units/string.rb', line 22 def %(*other) if other.first.is_a?(RubyUnits::Unit) other.first.to_s(self) else super end end |
#convert_to(other) ⇒ Unit
32 33 34 |
# File 'lib/ruby_units/string.rb', line 32 def convert_to(other) to_unit.convert_to(other) end |
#to_unit(other = nil) ⇒ RubyUnits::Unit
Make a string into a unit
13 14 15 |
# File 'lib/ruby_units/string.rb', line 13 def to_unit(other = nil) other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self) end |