diff options
author | Xavier Noria <fxn@hashref.com> | 2008-05-02 14:45:23 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-05-02 14:45:23 +0100 |
commit | 64092de25727c1943807bf5345107d90428135a0 (patch) | |
tree | 87977e3b0c839fb6adb417949676bb5384155526 /activesupport/lib/active_support/core_ext/range | |
parent | 87ec72bd8c4b5d178ba7a41e605bc9a8e27f9e67 (diff) | |
download | rails-64092de25727c1943807bf5345107d90428135a0.tar.gz rails-64092de25727c1943807bf5345107d90428135a0.tar.bz2 rails-64092de25727c1943807bf5345107d90428135a0.zip |
Improve documentation coverage and markup
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activesupport/lib/active_support/core_ext/range')
-rw-r--r-- | activesupport/lib/active_support/core_ext/range/include_range.rb | 8 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/range/overlaps.rb | 3 |
2 files changed, 11 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 index cd53cf154a..9a7d235695 100644 --- a/activesupport/lib/active_support/core_ext/range/include_range.rb +++ b/activesupport/lib/active_support/core_ext/range/include_range.rb @@ -7,6 +7,14 @@ module ActiveSupport #:nodoc: base.alias_method_chain :include?, :range end + # 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) operator = exclude_end? ? :< : :<= diff --git a/activesupport/lib/active_support/core_ext/range/overlaps.rb b/activesupport/lib/active_support/core_ext/range/overlaps.rb index 80ed1bba9d..43c69453e7 100644 --- a/activesupport/lib/active_support/core_ext/range/overlaps.rb +++ b/activesupport/lib/active_support/core_ext/range/overlaps.rb @@ -3,6 +3,9 @@ module ActiveSupport #:nodoc: module Range #:nodoc: # Check if Ranges overlap. module Overlaps + # Compare two ranges and see if they overlap eachother + # (1..5).overlaps?(4..6) # => true + # (1..5).overlaps?(7..9) # => false def overlaps?(other) include?(other.first) || other.include?(first) end |