Skip to content
This repository
Browse code

refactor Range#include? to handle ranges with floats

Conflicts:

	activesupport/lib/active_support/core_ext/range/include_range.rb
  • Loading branch information...
commit 71f59b72fec12834645d9cc0d6dc61f15dcfde68 1 parent 766eda3
Sergey Nartimov authored December 29, 2011 fxn committed December 30, 2011
5  activesupport/lib/active_support/core_ext/range/include_range.rb
@@ -9,9 +9,8 @@ class Range
9 9
   #  (5..9).include?(11) # => false
10 10
   def include_with_range?(value)
11 11
     if value.is_a?(::Range)
12  
-      operator = exclude_end? ? :< : :<=
13  
-      end_value = value.exclude_end? ? last.succ : last
14  
-      include_without_range?(value.first) && (value.last <=> end_value).send(operator, 0)
  12
+      operator = exclude_end? && !value.exclude_end? ? :< : :<=
  13
+      include_without_range?(value.first) && value.last.send(operator, last)
15 14
     else
16 15
       include_without_range?(value)
17 16
     end
4  activesupport/test/core_ext/range_ext_test.rb
@@ -53,6 +53,10 @@ def test_should_not_include_overlapping_last
53 53
     assert !(2..8).include?(5..9)
54 54
   end
55 55
 
  56
+  def test_should_include_identical_exclusive_with_floats
  57
+    assert (1.0...10.0).include?(1.0...10.0)
  58
+  end
  59
+
56 60
   def test_blockless_step
57 61
     assert_equal [1,3,5,7,9], (1..10).step(2)
58 62
   end

0 notes on commit 71f59b7

Please sign in to comment.
Something went wrong with that request. Please try again.