From 42723e3a0c74e25c45c0f763740a3115302da4ac Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Tue, 19 Jul 2005 12:58:01 +0000 Subject: Factor Fixnum and Bignum extensions into Integer class git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1863 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/active_support/core_ext/fixnum.rb | 12 ----------- .../lib/active_support/core_ext/fixnum/even_odd.rb | 24 ---------------------- .../active_support/core_ext/fixnum/inflections.rb | 15 -------------- .../lib/active_support/core_ext/integer.rb | 7 +++++++ .../active_support/core_ext/integer/even_odd.rb | 24 ++++++++++++++++++++++ .../active_support/core_ext/integer/inflections.rb | 15 ++++++++++++++ 6 files changed, 46 insertions(+), 51 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/fixnum.rb delete mode 100644 activesupport/lib/active_support/core_ext/fixnum/even_odd.rb delete mode 100644 activesupport/lib/active_support/core_ext/fixnum/inflections.rb create mode 100644 activesupport/lib/active_support/core_ext/integer.rb create mode 100644 activesupport/lib/active_support/core_ext/integer/even_odd.rb create mode 100644 activesupport/lib/active_support/core_ext/integer/inflections.rb (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/fixnum.rb b/activesupport/lib/active_support/core_ext/fixnum.rb deleted file mode 100644 index 519408fb0d..0000000000 --- a/activesupport/lib/active_support/core_ext/fixnum.rb +++ /dev/null @@ -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 \ 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 deleted file mode 100644 index c0e9da18fa..0000000000 --- a/activesupport/lib/active_support/core_ext/fixnum/even_odd.rb +++ /dev/null @@ -1,24 +0,0 @@ -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 multiple_of?(number) - self % number == 0 - end - - def even? - multiple_of? 2 - end - - def odd? - !even? - end - end - end - end -end diff --git a/activesupport/lib/active_support/core_ext/fixnum/inflections.rb b/activesupport/lib/active_support/core_ext/fixnum/inflections.rb deleted file mode 100644 index 13c4f1130a..0000000000 --- a/activesupport/lib/active_support/core_ext/fixnum/inflections.rb +++ /dev/null @@ -1,15 +0,0 @@ -require File.dirname(__FILE__) + '/../../inflector' -module ActiveSupport #:nodoc: - module CoreExtensions #:nodoc: - module Fixnum #:nodoc: - module Inflections - # 1.ordinalize # => "1st" - # 3.ordinalize # => "3rd" - # 10.ordinalize # => "10th" - def ordinalize - Inflector.ordinalize(self) - end - end - end - end -end diff --git a/activesupport/lib/active_support/core_ext/integer.rb b/activesupport/lib/active_support/core_ext/integer.rb new file mode 100644 index 0000000000..9346b88fd5 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/integer.rb @@ -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 diff --git a/activesupport/lib/active_support/core_ext/integer/even_odd.rb b/activesupport/lib/active_support/core_ext/integer/even_odd.rb new file mode 100644 index 0000000000..3762308cc3 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/integer/even_odd.rb @@ -0,0 +1,24 @@ +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module Integer #: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 multiple_of?(number) + self % number == 0 + end + + def even? + multiple_of? 2 + end + + def odd? + !even? + end + end + end + end +end diff --git a/activesupport/lib/active_support/core_ext/integer/inflections.rb b/activesupport/lib/active_support/core_ext/integer/inflections.rb new file mode 100644 index 0000000000..a86c4cc26c --- /dev/null +++ b/activesupport/lib/active_support/core_ext/integer/inflections.rb @@ -0,0 +1,15 @@ +require File.dirname(__FILE__) + '/../../inflector' +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module Integer #:nodoc: + module Inflections + # 1.ordinalize # => "1st" + # 3.ordinalize # => "3rd" + # 10.ordinalize # => "10th" + def ordinalize + Inflector.ordinalize(self) + end + end + end + end +end -- cgit v1.2.3