Sha256: 9420c7e451574edc6a820a05e850206df726bec6710a16832550be91c0d1c576
Contents?: true
Size: 355 Bytes
Versions: 17
Compression:
Stored size: 355 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('%<s>.3f', s: (abs.to_f / 1024**e)) s.sub(/\.?0*$/, ' ' + units[e]) end end
Version data entries
17 entries across 17 versions & 1 rubygems