Sha256: 8f52c00c164b0dea6bf0ba21f58586f492ab956e321da4c7aa2448b86fb9f44b

Contents?: true

Size: 656 Bytes

Versions: 1

Compression:

Stored size: 656 Bytes

Contents

module Polyfill
  module V2_4
    module Integer
      module Instance
        module Truncate
          module Method
            def truncate(ndigits = 0)
              ndigits = ndigits.to_int
              return super() if ndigits == 0
              return to_f if ndigits > 0

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

          if RUBY_VERSION < '2.4.0'
            refine ::Integer do
              include Method
            end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
polyfill-0.3.0 lib/polyfill/v2_4/integer/instance/truncate.rb