diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-06-21 07:00:28 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-06-21 07:00:28 +0000 |
commit | 6c8d354b8d9ca2fa62d0e062fa6346673dd15dbf (patch) | |
tree | 314efa0a4540a27b4218a4bdc3cf01e1b35dc537 /activesupport/lib | |
parent | b69199c1da3ef89bdbebb98084bcf6fe31732a53 (diff) | |
download | rails-6c8d354b8d9ca2fa62d0e062fa6346673dd15dbf.tar.gz rails-6c8d354b8d9ca2fa62d0e062fa6346673dd15dbf.tar.bz2 rails-6c8d354b8d9ca2fa62d0e062fa6346673dd15dbf.zip |
Added Fix/Bignum#multiple_of? which returns true on 14.multiple_of?(7) and false on 16.multiple_of?(7) #1464 [Thomas Fuchs] Added even? and odd? to work with Bignums in addition to Fixnums #1464 [Thomas Fuchs]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1462 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/fixnum.rb | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/fixnum/even_odd.rb | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/fixnum.rb b/activesupport/lib/active_support/core_ext/fixnum.rb index fecef1da52..e983d5c0f9 100644 --- a/activesupport/lib/active_support/core_ext/fixnum.rb +++ b/activesupport/lib/active_support/core_ext/fixnum.rb @@ -3,3 +3,7 @@ require File.dirname(__FILE__) + '/fixnum/even_odd' class Fixnum #:nodoc: include ActiveSupport::CoreExtensions::Fixnum::EvenOdd end + +class Bignum #:nodoc: + include ActiveSupport::CoreExtensions::Fixnum::EvenOdd +end
\ No newline at end of file diff --git a/activesupport/lib/active_support/core_ext/fixnum/even_odd.rb b/activesupport/lib/active_support/core_ext/fixnum/even_odd.rb index 1fa6b95846..c0e9da18fa 100644 --- a/activesupport/lib/active_support/core_ext/fixnum/even_odd.rb +++ b/activesupport/lib/active_support/core_ext/fixnum/even_odd.rb @@ -7,8 +7,12 @@ module ActiveSupport #:nodoc: # * 2.even? # => true # * 2.odd? # => false module EvenOdd + def multiple_of?(number) + self % number == 0 + end + def even? - self % 2 == 0 + multiple_of? 2 end def odd? |