Sha256: dc579306312aae0eefc61eeb515903e8a52c293183916e2a15f127e8f63e60a5

Contents?: true

Size: 760 Bytes

Versions: 3

Compression:

Stored size: 760 Bytes

Contents

module Polyfill
  module V2_4
    module Integer
      module Instance
        module Round
          module Method
            def round(ndigits = 0, half: nil)
              unless [nil, :down, :even, :up, 'down', 'even', 'up'].include?(half)
                raise ArgumentError, "invalid rounding mode: #{half}"
              end
              ndigits = ndigits.to_int
              return super() if ndigits == 0
              return to_f if ndigits > 0

              place = 10**-ndigits
              (to_f / place).round * place
            end
          end

          refine ::Integer do
            include Method
          end

          def self.included(base)
            base.include Method
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
polyfill-0.6.0 lib/polyfill/v2_4/integer/instance/round.rb
polyfill-0.5.0 lib/polyfill/v2_4/integer/instance/round.rb
polyfill-0.4.0 lib/polyfill/v2_4/integer/instance/round.rb