Sha256: 60a912de7e7360c41152add708b622a911ed382619c5c934a71fd567b996f2d0

Contents?: true

Size: 598 Bytes

Versions: 47

Compression:

Stored size: 598 Bytes

Contents

if Float.instance_method(:round).arity.zero?
  require 'backports/tools/alias_method_chain'
  require 'backports/tools/arguments'

  class Float
    def round_with_digits(ndigits=0)
      ndigits = Backports::coerce_to_int(ndigits)
      case
      when ndigits == 0
        round_without_digits
      when ndigits < 0
        p = 10 ** -ndigits
        p > abs ? 0 : (self / p).round * p
      else
        p = 10 ** ndigits
        prod = self * p
        prod.infinite? || prod.nan? ? self : prod.round.to_f / p
      end
    end
    Backports.alias_method_chain self, :round, :digits
  end
end

Version data entries

47 entries across 47 versions & 4 rubygems

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