Sha256: d045e44a404f0e4c41d34474fd624b217139ae680c07f9a474194fab932b7c9f

Contents?: true

Size: 572 Bytes

Versions: 7

Compression:

Stored size: 572 Bytes

Contents

# frozen_string_literal: true
# NOTE remove once minimum required Ruby version is at least 2.4
Float.prepend(Module.new do
  def truncate *args
    if args.length == 1
      if (precision = Integer args.shift) == 0
        super
      elsif precision > 0
        precision_factor = 10.0 ** precision
        (self * precision_factor).to_i / precision_factor
      else
        precision_factor = 10 ** precision.abs
        (self / precision_factor).to_i * precision_factor
      end
    else
      super
    end
  end
end) if (Float.instance_method :truncate).arity == 0

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
asciidoctor-2.0.3 lib/asciidoctor/core_ext/float/truncate.rb
asciidoctor-2.0.2 lib/asciidoctor/core_ext/float/truncate.rb
asciidoctor-2.0.1 lib/asciidoctor/core_ext/float/truncate.rb
asciidoctor-2.0.0 lib/asciidoctor/core_ext/float/truncate.rb
asciidoctor-2.0.0.rc.3 lib/asciidoctor/core_ext/float/truncate.rb
asciidoctor-2.0.0.rc.2 lib/asciidoctor/core_ext/float/truncate.rb
asciidoctor-2.0.0.rc.1 lib/asciidoctor/core_ext/float/truncate.rb