Permalink
Browse files

Added Fixnum#even? and Fixnum#odd?

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1094 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 97e39fc commit d08271e62f4cd5b3c42f3e385d9166f6e591cbaa @dhh dhh committed Apr 5, 2005
View
@@ -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]
View
@@ -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."
@@ -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
@@ -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

0 comments on commit d08271e

Please sign in to comment.