Class: Fixnum

Inherits:
Object
  • Object
show all
Defined in:
lib/collins_shell/monkeypatch.rb

Instance Method Summary collapse

Instance Method Details

#to_human_sizeObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/collins_shell/monkeypatch.rb', line 20

def to_human_size
  return "0 Bytes" if (self == 0)
  i = (Math.log(self) / Math.log(1024)).floor.to_i
  small = self / (1024 ** i)
  if i == 0 then
    "#{self} #{SIZE_ARRAY[i]}"
  else
    sprintf("%.2f %s", small, SIZE_ARRAY[i])
  end
end