mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Factor Fixnum and Bignum extensions into Integer class
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1863 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
83e2f6ae1e
commit
42723e3a0c
6 changed files with 17 additions and 18 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Factor Fixnum and Bignum extensions into Integer extensions [Nicholas Seckar]
|
||||
|
||||
* Hooked #ordinalize into Fixnum and Bignum classes. [Nicholas Seckar, danp]
|
||||
|
||||
* Added stripping of _id to humanize, so "employee_id" becomes "Employee" #1574 [Justin French]
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
require File.dirname(__FILE__) + '/fixnum/even_odd'
|
||||
require File.dirname(__FILE__) + '/fixnum/inflections'
|
||||
|
||||
class Fixnum #:nodoc:
|
||||
include ActiveSupport::CoreExtensions::Fixnum::EvenOdd
|
||||
include ActiveSupport::CoreExtensions::Fixnum::Inflections
|
||||
end
|
||||
|
||||
class Bignum #:nodoc:
|
||||
include ActiveSupport::CoreExtensions::Fixnum::EvenOdd
|
||||
include ActiveSupport::CoreExtensions::Fixnum::Inflections
|
||||
end
|
7
activesupport/lib/active_support/core_ext/integer.rb
Normal file
7
activesupport/lib/active_support/core_ext/integer.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.dirname(__FILE__) + '/integer/even_odd'
|
||||
require File.dirname(__FILE__) + '/integer/inflections'
|
||||
|
||||
class Integer #:nodoc:
|
||||
include ActiveSupport::CoreExtensions::Integer::EvenOdd
|
||||
include ActiveSupport::CoreExtensions::Integer::Inflections
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
module ActiveSupport #:nodoc:
|
||||
module CoreExtensions #:nodoc:
|
||||
module Fixnum #:nodoc:
|
||||
module Integer #:nodoc:
|
||||
# For checking if a fixnum is even or odd.
|
||||
# * 1.even? # => false
|
||||
# * 1.odd? # => true
|
|
@ -1,7 +1,7 @@
|
|||
require File.dirname(__FILE__) + '/../../inflector'
|
||||
module ActiveSupport #:nodoc:
|
||||
module CoreExtensions #:nodoc:
|
||||
module Fixnum #:nodoc:
|
||||
module Integer #:nodoc:
|
||||
module Inflections
|
||||
# 1.ordinalize # => "1st"
|
||||
# 3.ordinalize # => "3rd"
|
|
@ -1,7 +1,7 @@
|
|||
require 'test/unit'
|
||||
require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/fixnum'
|
||||
require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/integer'
|
||||
|
||||
class FixnumExtTest < Test::Unit::TestCase
|
||||
class IntegerExtTest < Test::Unit::TestCase
|
||||
def test_even
|
||||
assert [ -2, 0, 2, 4 ].all? { |i| i.even? }
|
||||
assert ![ -1, 1, 3 ].all? { |i| i.even? }
|
||||
|
@ -15,11 +15,12 @@ class FixnumExtTest < Test::Unit::TestCase
|
|||
def test_odd
|
||||
assert ![ -2, 0, 2, 4 ].all? { |i| i.odd? }
|
||||
assert [ -1, 1, 3 ].all? { |i| i.odd? }
|
||||
assert 1000000000000000000000000000000000000000000000000000000001.odd?
|
||||
end
|
||||
|
||||
def test_multiple_of
|
||||
assert [ -7, 0, 7, 14 ].all? { |i| i.multiple_of? 7 }
|
||||
assert ![ -7, 0, 7, 14 ].all? { |i| i.multiple_of? 6 }
|
||||
[ -7, 0, 7, 14 ].each { |i| assert i.multiple_of?(7) }
|
||||
[ -7, 7, 14 ].each { |i| assert ! i.multiple_of?(6) }
|
||||
# test with a prime
|
||||
assert !22953686867719691230002707821868552601124472329079.multiple_of?(2)
|
||||
assert !22953686867719691230002707821868552601124472329079.multiple_of?(3)
|
||||
|
@ -32,5 +33,6 @@ class FixnumExtTest < Test::Unit::TestCase
|
|||
# It's results are tested comprehensively in the inflector test cases.
|
||||
assert_equal '1st', 1.ordinalize
|
||||
assert_equal '8th', 8.ordinalize
|
||||
1000000000000000000000000000000000000000000000000000000000000000000000.ordinalize
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue