From 738fd3d4a64c13523ce607357deae45d2f9a0ab5 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 1 Nov 2009 19:50:21 +0100 Subject: AS guide: documents Numeric#bytes and friends --- .../source/active_support_core_extensions.textile | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 147366c1a6..a2cfbff0ce 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/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: + + +bytes +kilobytes +megabytes +gigabytes +terabytes +petabytes +exabytes + + +They return the corresponding amount of bytes, using a conversion factor of 1024: + + +2.kilobytes # => 2048 +3.megabytes # => 3145728 +3.5.gigabytes # => 3758096384 +-4.exabytes # => -4611686018427387904 + + +Singular forms are aliased so you are able to say: + + +1.megabyte # => 1024 + h3. Extensions to +Integer+ -- cgit v1.2.3