aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/range/include_range.rb
diff options
context:
space:
mode:
authorYuki Nishijima <mail@yukinishijima.net>2015-04-13 20:15:08 -0800
committerYuki Nishijima <mail@yukinishijima.net>2015-04-14 10:13:14 -0700
commitd3684c4154df66059ba77d022eca285563b8f506 (patch)
treeab92afe5fe06f5bd925ff9279873030d0a72d86f /activesupport/lib/active_support/core_ext/range/include_range.rb
parent34d3a6095100245283861ef480a54d0643bbee4c (diff)
downloadrails-d3684c4154df66059ba77d022eca285563b8f506.tar.gz
rails-d3684c4154df66059ba77d022eca285563b8f506.tar.bz2
rails-d3684c4154df66059ba77d022eca285563b8f506.zip
Use #prepend rather than using 2 aliases
Diffstat (limited to 'activesupport/lib/active_support/core_ext/range/include_range.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/range/include_range.rb40
1 files changed, 20 insertions, 20 deletions
diff --git a/activesupport/lib/active_support/core_ext/range/include_range.rb b/activesupport/lib/active_support/core_ext/range/include_range.rb
index 9d20920dd0..c69e1e3fb9 100644
--- a/activesupport/lib/active_support/core_ext/range/include_range.rb
+++ b/activesupport/lib/active_support/core_ext/range/include_range.rb
@@ -1,23 +1,23 @@
-class Range
- # Extends the default Range#include? to support range comparisons.
- # (1..5).include?(1..5) # => true
- # (1..5).include?(2..3) # => true
- # (1..5).include?(2..6) # => false
- #
- # The native Range#include? behavior is untouched.
- # ('a'..'f').include?('c') # => true
- # (5..9).include?(11) # => false
- def include_with_range?(value)
- if value.is_a?(::Range)
- # 1...10 includes 1..9 but it does not include 1..10.
- operator = exclude_end? && !value.exclude_end? ? :< : :<=
- include_without_range?(value.first) && value.last.send(operator, last)
- else
- include_without_range?(value)
+module ActiveSupport
+ module IncludeWithRange #:nodoc:
+ # Extends the default Range#include? to support range comparisons.
+ # (1..5).include?(1..5) # => true
+ # (1..5).include?(2..3) # => true
+ # (1..5).include?(2..6) # => false
+ #
+ # The native Range#include? behavior is untouched.
+ # ('a'..'f').include?('c') # => true
+ # (5..9).include?(11) # => false
+ def include?(value)
+ if value.is_a?(::Range)
+ # 1...10 includes 1..9 but it does not include 1..10.
+ operator = exclude_end? && !value.exclude_end? ? :< : :<=
+ super(value.first) && value.last.send(operator, last)
+ else
+ super
+ end
end
end
- # TODO: change to Module#prepend as soon as the fix is backported to MRI 2.2:
- # https://bugs.ruby-lang.org/issues/10847
- alias_method :include_without_range?, :include?
- alias_method :include?, :include_with_range?
end
+
+Range.prepend(ActiveSupport::IncludeWithRange)