diff options
author | Sergey Nartimov <just.lest@gmail.com> | 2011-12-29 10:50:15 +0300 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2011-12-30 02:24:46 -0800 |
commit | 71f59b72fec12834645d9cc0d6dc61f15dcfde68 (patch) | |
tree | b622327b0912a8c148de9f772b309e407790a7bf | |
parent | 766eda3e11c4fd7c1a99c81d442ef5f4e0a0460d (diff) | |
download | rails-71f59b72fec12834645d9cc0d6dc61f15dcfde68.tar.gz rails-71f59b72fec12834645d9cc0d6dc61f15dcfde68.tar.bz2 rails-71f59b72fec12834645d9cc0d6dc61f15dcfde68.zip |
refactor Range#include? to handle ranges with floats
Conflicts:
activesupport/lib/active_support/core_ext/range/include_range.rb
-rw-r--r-- | activesupport/lib/active_support/core_ext/range/include_range.rb | 5 | ||||
-rw-r--r-- | activesupport/test/core_ext/range_ext_test.rb | 4 |
2 files changed, 6 insertions, 3 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 0246627467..38a90490e6 100644 --- a/activesupport/lib/active_support/core_ext/range/include_range.rb +++ b/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 diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb index 1424fa4aca..f9fb4f833a 100644 --- a/activesupport/test/core_ext/range_ext_test.rb +++ b/activesupport/test/core_ext/range_ext_test.rb @@ -53,6 +53,10 @@ class RangeTest < Test::Unit::TestCase 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 |