Sha256: 8fba78247700e918ea736e36cf5cb9f5f850c4527b818613995afd69cd382aaf
Contents?: true
Size: 349 Bytes
Versions: 18
Compression:
Stored size: 349 Bytes
Contents
# frozen_string_literal: true # Hack of the Numeric class class Numeric # @return [ String ] A human readable string of the value def bytes_to_human units = %w[B KB MB GB TB] e = abs.zero? ? abs : (Math.log(abs) / Math.log(1024)).floor s = format('%.3f', (abs.to_f / 1024**e)) s.sub(/\.?0*$/, ' ' + units[e]) end end
Version data entries
18 entries across 18 versions & 1 rubygems