Sha256: e1493506e588744df6d69846bcc64147164b2dced1fd179068cddf1bda6a3d52

Contents?: true

Size: 781 Bytes

Versions: 2

Compression:

Stored size: 781 Bytes

Contents

# Test to see if Fixnum/Bignum are deprecated, which implies we are in ruby 2.4
# or greater

# Silence any deprecation warnings
warn_level = $VERBOSE
$VERBOSE = nil
v2_4 = Fixnum == Integer
$VERBOSE = warn_level

if v2_4
  class Integer
    alias_method :orig_multiply, :*

    def *(other)
      other.is_a?(Distance) ? other * self : orig_multiply(other)
    end
  end
else
  # In ruby versions before 2.4, multiplication was defined in Bignum and Fixnum,
  # not in Integer
  class Bignum
    alias_method :orig_multiply, :*

    def *(other)
      other.is_a?(Distance) ? other * self : orig_multiply(other)
    end
  end

  class Fixnum
    alias_method :orig_multiply, :*

    def *(other)
      other.is_a?(Distance) ? other * self : orig_multiply(other)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
distance-1.0.0 lib/distance/core_ext/integer.rb
distance-0.3.1 lib/distance/core_ext/integer.rb