module RubyUnits::String
Extra methods for converting [String] objects to [RubyUnits::Unit] objects and using string formatting with Units.
Public Instance Methods
%(*other)
click to toggle source
Format unit output using formatting codes @example ‘%0.2f’ % ‘1 mm’.to_unit => ‘1.00 mm’
@param other [RubyUnits::Unit, Object] @return [String]
Calls superclass method
# 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)
click to toggle source
@param (see RubyUnits::Unit#convert_to
) @return (see RubyUnits::Unit#convert_to
)
# File lib/ruby_units/string.rb, line 32 def convert_to(other) to_unit.convert_to(other) end
to_unit(other = nil)
click to toggle source
Make a string into a unit
@param other [RubyUnits::Unit, String] unit to convert to @return [RubyUnits::Unit]
# 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