module NumericWithUnit::CORE_EXT::String

Public Instance Methods

to_nwu(mthd=:to_r) click to toggle source
# File lib/numeric_with_unit/core_ext.rb, line 14
def to_nwu(mthd=:to_r)
  # TODO: 適当なのでもう少しいい感じに。いい感じに
  m = self.match /.*?(?=[\s\(\[])/
  value = m.to_s
  unit = m.post_match.strip.gsub(/^\[|\]$/, '')
  NumericWithUnit.new(value.__send__(mthd), unit)
end