"Fossies" - the Fresh Open Source Software Archive

Member "asciidoctor-2.0.10/lib/asciidoctor/core_ext/float/truncate.rb" (1 Jun 2019, 630 Bytes) of package /linux/www/asciidoctor-2.0.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 # frozen_string_literal: true
    2 # NOTE remove once minimum required Ruby version is at least 2.4
    3 # NOTE use `send :prepend` to be nice to Ruby 2.0
    4 Float.send :prepend, (Module.new do
    5   def truncate *args
    6     if args.length == 1
    7       if (precision = Integer args.shift) == 0
    8         super
    9       elsif precision > 0
   10         precision_factor = 10.0 ** precision
   11         (self * precision_factor).to_i / precision_factor
   12       else
   13         precision_factor = 10 ** precision.abs
   14         (self / precision_factor).to_i * precision_factor
   15       end
   16     else
   17       super
   18     end
   19   end
   20 end) if (Float.instance_method :truncate).arity == 0