Sha256: 5b9eb45eadca1c779a614a35c45ff5a153d9c10dbfd45e336cf941f5f048ddef

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

# Extend Numeric class with Math module methods.
class Numeric

    extend Math

    # ------------------------------------------------------------
    # Add Math one-arg methods to Numeric.

    oneArg = [:cos, :sin, :tan, :acos, :asin, :atan, :cosh, :sinh, :tanh,
              :acosh, :asinh, :atanh, :exp, :log2, :log10,
              :sqrt, :cbrt, :frexp, :erf, :erfc, :gamma, :lgamma]

    oneArg.each do |method|
        define_method( method ) { Numeric.send( method, self ) }
    end

    public_class_method( *oneArg )


    # ------------------------------------------------------------
    # Add Math two-arg methods to Numeric.

    twoArg = [ :atan2, :log, :hypot, :ldexp ]

    twoArg.each do |method|
        define_method( method ) { |arg2| Numeric.send( method, self, arg2 ) }
    end

    public_class_method( *twoArg )


    # ------------------------------------------------------------
    # Additional methods:

    # Convert self to rad.
    def to_rad
        self / 180.0 * Math::PI
    end

    # Convert self to dec.
    def to_deg
        self * 180.0 / Math::PI
    end

end

require_relative 'version'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
numeric_math-0.0.2 lib/numeric_math.rb
numeric_math-0.0.1 lib/numeric_math.rb