Sha256: e54596a10994334a4a3fbb9432d146c815760df094c47accb1315aea3f689a16

Contents?: true

Size: 985 Bytes

Versions: 5

Compression:

Stored size: 985 Bytes

Contents

unless (Math.log(2, 2) rescue false)
    # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Math.html]
  class << Math
    require 'backports/tools'

    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

    # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Math.html]
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
backports-3.3.1 lib/backports/1.9.1/math/log.rb
backports-3.3.0 lib/backports/1.9.1/math/log.rb
backports-3.2.0 lib/backports/1.9.1/math/log.rb
backports-3.1.1 lib/backports/1.9.1/math/log.rb
backports-3.1.0 lib/backports/1.9.1/math/log.rb