Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@lest lest authored fxn committed
View
5 activesupport/lib/active_support/core_ext/range/include_range.rb
@@ -9,9 +9,8 @@ class Range
# (5..9).include?(11) # => false
def include_with_range?(value)
if value.is_a?(::Range)
- operator = exclude_end? ? :< : :<=
- end_value = value.exclude_end? ? last.succ : last
- include_without_range?(value.first) && (value.last <=> end_value).send(operator, 0)
+ operator = exclude_end? && !value.exclude_end? ? :< : :<=
+ include_without_range?(value.first) && value.last.send(operator, last)
else
include_without_range?(value)
end
View
4 activesupport/test/core_ext/range_ext_test.rb
@@ -53,6 +53,10 @@ def test_should_not_include_overlapping_last
assert !(2..8).include?(5..9)
end
+ def test_should_include_identical_exclusive_with_floats
+ assert (1.0...10.0).include?(1.0...10.0)
+ end
+
def test_blockless_step
assert_equal [1,3,5,7,9], (1..10).step(2)
end

0 comments on commit 71f59b7

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