Sha256: e43327c14e62f5a3aac9a73a61b39be4ebc6f78908feab652f9f5a3ebbb6af8d

Contents?: true

Size: 548 Bytes

Versions: 23

Compression:

Stored size: 548 Bytes

Contents

class Integer
  Backports.alias_method self, :magnitude, :abs

  if instance_method(:round).arity.zero?
    def round_with_digits(ndigits=0)
      ndigits = Backports::coerce_to_int(ndigits)
      case
      when ndigits.zero?
        self
      when ndigits > 0
        Float(self)
      else
        pow = 10 ** (-ndigits)
        remain = self % pow
        comp = self < 0 ? :<= : :<
        remain -= pow unless remain.send(comp, pow / 2)
        self - remain
      end
    end
    Backports.alias_method_chain self, :round, :digits
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
backports-3.0.3 lib/backports/1.9.1/integer.rb
backports-3.0.2 lib/backports/1.9.1/integer.rb
backports-3.0.1 lib/backports/1.9.1/integer.rb
backports-3.0.0 lib/backports/1.9.1/integer.rb
backports-2.8.2 lib/backports/1.9.1/integer.rb
backports-2.8.1 lib/backports/1.9.1/integer.rb
backports-2.8.0 lib/backports/1.9.1/integer.rb
backports-2.7.1 lib/backports/1.9.1/integer.rb
backports-2.7.0 lib/backports/1.9.1/integer.rb
backports-2.6.7 lib/backports/1.9.1/integer.rb
backports-2.6.6 lib/backports/1.9.1/integer.rb
backports-2.6.5 lib/backports/1.9.1/integer.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/backports-2.6.4/lib/backports/1.9.1/integer.rb
backports-2.6.4 lib/backports/1.9.1/integer.rb
backports-2.6.3 lib/backports/1.9.1/integer.rb
backports-2.6.2 lib/backports/1.9.1/integer.rb
backports-2.6.1 lib/backports/1.9.1/integer.rb
backports-2.6.0 lib/backports/1.9.1/integer.rb
backports-2.5.3 lib/backports/1.9.1/integer.rb
backports-2.5.2 lib/backports/1.9.1/integer.rb