From 952e9d9005b775827b17227e040499d0324bb928 Mon Sep 17 00:00:00 2001 From: Sergey Nartimov Date: Thu, 29 Dec 2011 10:50:15 +0300 Subject: refactor Range#include? to handle ranges with floats --- activesupport/lib/active_support/core_ext/range/include_range.rb | 3 ++- activesupport/test/core_ext/range_ext_test.rb | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'activesupport') 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 c9986d4724..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,7 +9,8 @@ class Range # (5..9).include?(11) # => false def include_with_range?(value) if value.is_a?(::Range) - min <= value.min && max >= value.max + 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 f4b773e5fb..7a620305f3 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 -- cgit v1.2.3