Sha256: 970ab57cc27004509857e326765a92d328881feaf4759048ff004a703f98902c

Contents?: true

Size: 936 Bytes

Versions: 47

Compression:

Stored size: 936 Bytes

Contents

unless (Math.log(2, 2) rescue false)
  require 'backports/tools/alias_method_chain'
  require 'backports/tools/arguments'

  class << Math
    # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Math.html]
    def log_with_optional_base(numeric, base = Backports::Undefined)
      if base.equal?(Backports::Undefined)
        # Math.log(n) in 1.9.1 no longer accepts string arguments as it
        # did on 1.8.x, but we won't risk redefining existing behavior
        # when called with just one argument.
        log_without_optional_base(numeric)
      else
        # Math.log(n, b) in 1.9.1 does not accept string arguments:
        raise TypeError, "can't convert String into Float" if numeric.is_a?(String) || base.is_a?(String)
        log_without_optional_base(numeric) / log_without_optional_base(base)
      end
    end
    Backports.alias_method_chain self, :log, :optional_base
  end
end

Version data entries

47 entries across 47 versions & 4 rubygems

Version Path
backports-3.25.0 lib/backports/1.9.1/math/log.rb
backports-3.24.1 lib/backports/1.9.1/math/log.rb
backports-3.24.0 lib/backports/1.9.1/math/log.rb
backports-3.23.0 lib/backports/1.9.1/math/log.rb
backports-3.22.1 lib/backports/1.9.1/math/log.rb
backports-3.22.0 lib/backports/1.9.1/math/log.rb
backports-3.21.0 lib/backports/1.9.1/math/log.rb
backports-3.20.2 lib/backports/1.9.1/math/log.rb
backports-3.20.1 lib/backports/1.9.1/math/log.rb
backports-3.20.0 lib/backports/1.9.1/math/log.rb
backports-3.19.0 lib/backports/1.9.1/math/log.rb
backports-3.18.2 lib/backports/1.9.1/math/log.rb
backports-3.18.1 lib/backports/1.9.1/math/log.rb
backports-3.18.0 lib/backports/1.9.1/math/log.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/backports-3.12.0/lib/backports/1.9.1/math/log.rb
backports-3.17.2 lib/backports/1.9.1/math/log.rb
backports-3.17.1 lib/backports/1.9.1/math/log.rb
backports-3.17.0 lib/backports/1.9.1/math/log.rb
backports-3.16.1 lib/backports/1.9.1/math/log.rb
backports-3.16.0 lib/backports/1.9.1/math/log.rb