aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-04-05 16:54:17 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-04-05 16:54:17 +0000
commitd08271e62f4cd5b3c42f3e385d9166f6e591cbaa (patch)
treed050396a511489eb180d3b38156d1db426916508 /activesupport
parent97e39fcb6418a5b1d5254ebb1059df796db21701 (diff)
downloadrails-d08271e62f4cd5b3c42f3e385d9166f6e591cbaa.tar.gz
rails-d08271e62f4cd5b3c42f3e385d9166f6e591cbaa.tar.bz2
rails-d08271e62f4cd5b3c42f3e385d9166f6e591cbaa.zip
Added Fixnum#even? and Fixnum#odd?
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1094 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/Rakefile6
-rw-r--r--activesupport/lib/active_support/core_ext/fixnum/even_odd.rb20
-rw-r--r--activesupport/test/core_ext/fixnum_ext_test.rb14
4 files changed, 39 insertions, 3 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index c323bd2ea5..792388d2b6 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added Fixnum#even? and Fixnum#odd?
+
* Fixed problem with classes being required twice. Object#const_missing now uses require_dependency to load files. It used to use require_or_load which would cause models to be loaded twice, which was not good for validations and other class methods #971 [Nicholas Seckar]
diff --git a/activesupport/Rakefile b/activesupport/Rakefile
index 99e49e9083..51294d4de6 100644
--- a/activesupport/Rakefile
+++ b/activesupport/Rakefile
@@ -58,13 +58,13 @@ end
desc "Publish the beta gem"
task :pgem => [:package] do
- Rake::SshFilePublisher.new("davidhh@comox.textdrive.com", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
- `ssh davidhh@comox.textdrive.com './gemupdate.sh'`
+ Rake::SshFilePublisher.new("davidhh@wrath.rubyonrails.com", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
+ `ssh davidhh@wrath.rubyonrails.com './gemupdate.sh'`
end
desc "Publish the API documentation"
task :pdoc => [:rdoc] do
- Rake::SshDirPublisher.new("davidhh@comox.textdrive.com", "public_html/as", "doc").upload
+ Rake::SshDirPublisher.new("davidhh@wrath.rubyonrails.com", "public_html/as", "doc").upload
end
desc "Publish the release files to RubyForge."
diff --git a/activesupport/lib/active_support/core_ext/fixnum/even_odd.rb b/activesupport/lib/active_support/core_ext/fixnum/even_odd.rb
new file mode 100644
index 0000000000..1fa6b95846
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/fixnum/even_odd.rb
@@ -0,0 +1,20 @@
+module ActiveSupport #:nodoc:
+ module CoreExtensions #:nodoc:
+ module Fixnum #: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 even?
+ self % 2 == 0
+ end
+
+ def odd?
+ !even?
+ end
+ end
+ end
+ end
+end
diff --git a/activesupport/test/core_ext/fixnum_ext_test.rb b/activesupport/test/core_ext/fixnum_ext_test.rb
new file mode 100644
index 0000000000..627c282b8b
--- /dev/null
+++ b/activesupport/test/core_ext/fixnum_ext_test.rb
@@ -0,0 +1,14 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/fixnum'
+
+class FixnumExtTest < Test::Unit::TestCase
+ def test_even
+ assert [ -2, 0, 2, 4 ].all? { |i| i.even? }
+ assert ![ -1, 1, 3 ].all? { |i| i.even? }
+ end
+
+ def test_odd
+ assert ![ -2, 0, 2, 4 ].all? { |i| i.odd? }
+ assert [ -1, 1, 3 ].all? { |i| i.odd? }
+ end
+end