mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added Fixnum#even? and Fixnum#odd?
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1094 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
97e39fcb64
commit
d08271e62f
4 changed files with 39 additions and 3 deletions
|
@ -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]
|
||||
|
||||
|
||||
|
|
|
@ -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."
|
||||
|
|
20
activesupport/lib/active_support/core_ext/fixnum/even_odd.rb
Normal file
20
activesupport/lib/active_support/core_ext/fixnum/even_odd.rb
Normal file
|
@ -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
|
14
activesupport/test/core_ext/fixnum_ext_test.rb
Normal file
14
activesupport/test/core_ext/fixnum_ext_test.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue