diff options
author | Nicholas Seckar <nseckar@gmail.com> | 2005-07-19 12:58:01 +0000 |
---|---|---|
committer | Nicholas Seckar <nseckar@gmail.com> | 2005-07-19 12:58:01 +0000 |
commit | 42723e3a0c74e25c45c0f763740a3115302da4ac (patch) | |
tree | f01b1d6c055a6b3051945f2aa4c23268e2dc32f6 /activesupport/lib/active_support/core_ext/integer | |
parent | 83e2f6ae1e1d4c6863b7c0514d55d7641fbd7513 (diff) | |
download | rails-42723e3a0c74e25c45c0f763740a3115302da4ac.tar.gz rails-42723e3a0c74e25c45c0f763740a3115302da4ac.tar.bz2 rails-42723e3a0c74e25c45c0f763740a3115302da4ac.zip |
Factor Fixnum and Bignum extensions into Integer class
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1863 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/integer')
-rw-r--r-- | activesupport/lib/active_support/core_ext/integer/even_odd.rb | 24 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/integer/inflections.rb | 15 |
2 files changed, 39 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/integer/even_odd.rb b/activesupport/lib/active_support/core_ext/integer/even_odd.rb new file mode 100644 index 0000000000..3762308cc3 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/integer/even_odd.rb @@ -0,0 +1,24 @@ +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module Integer #:nodoc: + # For checking if a fixnum is even or odd. + # * 1.even? # => false + # * 1.odd? # => true + # * 2.even? # => true + # * 2.odd? # => false + module EvenOdd + def multiple_of?(number) + self % number == 0 + end + + def even? + multiple_of? 2 + end + + def odd? + !even? + end + end + end + end +end diff --git a/activesupport/lib/active_support/core_ext/integer/inflections.rb b/activesupport/lib/active_support/core_ext/integer/inflections.rb new file mode 100644 index 0000000000..a86c4cc26c --- /dev/null +++ b/activesupport/lib/active_support/core_ext/integer/inflections.rb @@ -0,0 +1,15 @@ +require File.dirname(__FILE__) + '/../../inflector' +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module Integer #:nodoc: + module Inflections + # 1.ordinalize # => "1st" + # 3.ordinalize # => "3rd" + # 10.ordinalize # => "10th" + def ordinalize + Inflector.ordinalize(self) + end + end + end + end +end |