Rails File Size methods on Fixnum

As a Rails developer I have often seen the shorthands for specifying different dates using the built-in methods on Fixnum. For example, if you want to specify the date for 5 days ago, you can simply use:


However, what I didn’t know was that there is a similar shorthand for specifying file sizes – I stumbled across this while trying to upload files directly to S3.

100.bytes      # 100

100.kilobytes  # 102400

100.megabytes  # 104857600

100.gigabytes  # 107374182400

100.terabytes  # 109951162777600

Pretty neat! Happy coding.