class String

Public Instance Methods

__to_r__()
Alias for: to_r
imgsuffix() click to toggle source

拡張子が画像ならばその拡張子を返す

@return [String]
# File lib/kaki/utils/imgsuffix.rb, line 4
def imgsuffix
  [".jpg", ".gif", ".png", ".jpeg", ".bmp", ".JPG", ".GIF", ".PNG", ".JPEG", ".BMP"].each do |sf|
    return sf if include?(sf)
  end
  ""
end
to_r() click to toggle source

循環小数を分数に直す

@return [Rational]
# File lib/kaki/utils/rec_decimal.rb, line 32
def to_r
  st = delete(" ")
  return st.__to_r__ unless (m = /^([^\d]?)(\d+)\.(\d*)\((\d+)\)$/.match(st))
  f = (m[1] == "-") ? -1 : 1
  
  result = (m[2] + "." + m[3]).__to_r__
  l = m[4].length
  result += Rational(m[4].to_i, 10 ** l - 1) * Rational(1, 10) ** m[3].length
  result * f
end
Also aliased as: __to_r__