Permalink
Browse files

AS guide: documents Numeric#bytes and friends

  • Loading branch information...
fxn committed Nov 1, 2009
1 parent 106b78d commit 738fd3d4a64c13523ce607357deae45d2f9a0ab5
Showing with 28 additions and 1 deletion.
  1. +28 −1 railties/guides/source/active_support_core_extensions.textile
@@ -783,7 +783,34 @@ The call +str.last(n)+ is equivalent to +str.from(-n)+ if +n+ > 0, and returns a
h3. Extensions to +Numeric+
-...
+h4. Bytes
+
+All numbers respond to these methods:
+
+<ruby>
+bytes
+kilobytes
+megabytes
+gigabytes
+terabytes
+petabytes
+exabytes
+</ruby>
+
+They return the corresponding amount of bytes, using a conversion factor of 1024:
+
+<ruby>
+2.kilobytes # => 2048
+3.megabytes # => 3145728
+3.5.gigabytes # => 3758096384
+-4.exabytes # => -4611686018427387904
+</ruby>
+
+Singular forms are aliased so you are able to say:
+
+<ruby>
+1.megabyte # => 1024
+</ruby>
h3. Extensions to +Integer+

0 comments on commit 738fd3d

Please sign in to comment.