aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_support_overview.textile
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2009-08-01 03:21:10 +0200
committerXavier Noria <fxn@hashref.com>2009-08-01 03:21:10 +0200
commitb082cfa1e6bf5fa2c4612de96c9a38d633cecf6b (patch)
tree7c5e5c9e2b2dee1732a8372f30f26fb61d538fd0 /railties/guides/source/active_support_overview.textile
parentf320c994dbf0c1b0c03cd2ddc64aa52a4f5859b8 (diff)
downloadrails-b082cfa1e6bf5fa2c4612de96c9a38d633cecf6b.tar.gz
rails-b082cfa1e6bf5fa2c4612de96c9a38d633cecf6b.tar.bz2
rails-b082cfa1e6bf5fa2c4612de96c9a38d633cecf6b.zip
AS guide: explains a few extensions to Integer
Diffstat (limited to 'railties/guides/source/active_support_overview.textile')
-rw-r--r--railties/guides/source/active_support_overview.textile35
1 files changed, 34 insertions, 1 deletions
diff --git a/railties/guides/source/active_support_overview.textile b/railties/guides/source/active_support_overview.textile
index 4157694844..66206a7791 100644
--- a/railties/guides/source/active_support_overview.textile
+++ b/railties/guides/source/active_support_overview.textile
@@ -638,7 +638,40 @@ h3. Extensions to +Numeric+
h3. Extensions to +Integer+
-...
+h4. +multiple_of?+
+
+The method +multiple_of?+ tests whether an integer is multiple of the argument:
+
+<ruby>
+2.multiple_of?(1) # => true
+1.multiple_of?(2) # => false
+</ruby>
+
+WARNING: Due the way it is implemented the argument must be nonzero, otherwise +ZeroDivisionError+ is raised.
+
+h4. +even?+ and +odd?+
+
+Integers in Ruby 1.8.7 and above respond to +even?+ and +odd?+, Active Support defines them for older versions:
+
+<ruby>
+-1.even? # => false
+-1.odd? # => true
+ 0.even? # => true
+ 0.odd? # => false
+ 2.even? # => true
+ 2.odd? # => false
+</ruby>
+
+h4. +ordinalize+
+
+The method +ordinalize+ returns the ordinal string corresponding to the receiver integer:
+
+<ruby>
+1.ordinalize # => "1st"
+2.ordinalize # => "2nd"
+53.ordinalize # => "53rd"
+2009.ordinalize # => "2009th"
+</ruby>
h3. Extensions to +Float+