title: Pretty file size in Ruby?
body: <p>I'm trying to make a method that converts an integer that represents bytes to a string with a 'prettied up' format.</p>
  
  <p>Here's my half-working attempt:</p>
  
  <pre><code>class Integer
    def to_filesize
      {
        'B'  =&gt; 1024,
        'KB' =&gt; 1024 * 1024,
        'MB' =&gt; 1024 * 1024 * 1024,
        'GB' =&gt; 1024 * 1024 * 1024 * 1024,
        'TB' =&gt; 1024 * 1024 * 1024 * 1024 * 1024
      }.each_pair { |e, s| return "#{s / self}#{e}" if self &lt; s }
    end
  end
  </code></pre>
  
  <p>What am I doing wrong?</p>