diff options
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.rb | 24 |
1 files changed, 24 insertions, 0 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 new file mode 100644 index 0000000000..a6b4e9ff64 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/range/include_range.rb @@ -0,0 +1,24 @@ +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module Range #:nodoc: + # Check if a Range includes another Range + module IncludeRange + + def self.included(klass) #:nodoc: + klass.send(:alias_method_chain, :include?, :range) + end + + def include_with_range?(value) + if value.is_a?(::Range) + operator = exclude_end? ? :< : :<= + end_value = value.exclude_end? ? last.succ : last + include?(value.first) && (value.last <=> end_value).send(operator, 0) + else + include_without_range?(value) + end + end + + end + end + end +end
\ No newline at end of file |