Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/oode/ext/ext.rb
Overview
Allow numbers to be formatted with human readable data sizes.
Instance Method Summary collapse
Instance Method Details
#to_human ⇒ Object
11 12 13 14 15 16 |
# File 'lib/oode/ext/ext.rb', line 11 def to_human units = %w{B KB MB GB TB} e = (Math.log(self)/Math.log(1024)).floor s = "%.3f" % (to_f / 1024**e) s.sub(/\.?0*$/, units[e]) end |