Sha256: 442c7a577fc518b6db138b88c148dd1e9b89e3c16a04112f98a30927f6e76800

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

require 'rational'
require 'bigdecimal'
require 'complex'

class String
  def numeric?
    complex?
  end

  def complex?
    !!Complex(self) rescue false
  end

  def rational?
    !!Rational(self) rescue false
  end

  def integer?
    !!Integer(self) rescue false
  end

  def float?
    !!Float(self) rescue false
  end

  def decimal?
    !!BigDecimal(self) rescue false
  end
end

class Symbol
  def numeric?
    to_s.numeric?
  end

  def rational?
    to_s.rational?
  end

  def complex?
    to_s.complex?
  end

  def integer?
    to_s.complex?
  end

  def float?
    to_s.float?
  end

  def decimal?
    to_s.decimal?
  end
end

class Numeric
  def numeric?
    true
  end
end

class Complex
  def complex?
    true
  end
end

class Float
  def float?
    true
  end
end

class Rational
  def rational?
    true
  end
end

class BigDecimal
  def decimal?
    true
  end
end

module Kernel
  def numeric?
    false
  end

  def complex?
    false
  end

  def rational?
    false
  end

  def integer?
    false
  end

  def float?
    false
  end

  def decimal?
    false
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
numeric-0.2.0 lib/numeric.rb