Class: String
Instance Method Summary collapse
-
#%(*args) ⇒ String
format unit output using formating codes.
- #convert_to(other) ⇒ Unit
-
#to_unit(other = nil) ⇒ Unit
(also: #unit, #u)
make a string into a unit.
- #unit_format ⇒ Object
Instance Method Details
#%(*args) ⇒ String
format unit output using formating codes
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby_units/string.rb', line 16 def %(*args) return "" if self.empty? case when args.first.is_a?(RubyUnits::Unit) args.first.to_s(self) when (!defined?(Uncertain).nil? && args.first.is_a?(Uncertain)) args.first.to_s(self) when args.first.is_a?(Complex) args.first.to_s else unit_format(*args) end end |
#convert_to(other) ⇒ Unit
32 33 34 |
# File 'lib/ruby_units/string.rb', line 32 def convert_to(other) self.unit.convert_to(other) end |
#to_unit(other = nil) ⇒ Unit Also known as: unit, u
make a string into a unit
5 6 7 |
# File 'lib/ruby_units/string.rb', line 5 def to_unit(other = nil) other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self) end |
#unit_format ⇒ Object
12 |
# File 'lib/ruby_units/string.rb', line 12 alias :unit_format :% |