Remove attempt at spec-compliant Range#max and Range#min from core
MODIFY
mrblib/range.rb
mrblib/range.rb
@@ -65,67 +65,4 @@ end
# ISO 15.2.14.3
class Range
include Enumerable
-
- def max(&block)
- val = self.first
- last = self.last
- # numerics are special
- if (val.kind_of?(Fixnum) || val.kind_of?(Float)) && (last.kind_of?(Fixnum) || last.kind_of?(Float))
- return nil if val > last
- return nil if val == last && exclude_end?
-
- max = last
- max -= 1 if exclude_end?
- max = val if block && block.call(val, last) > 0
- return max
- end
-
- max = nil
- each do |item|
- max =
- if max.nil?
- item
- elsif block && block.call(max, item) > 0
- item
- elsif item > max
- item
- else
- max
- end
- end
- max
- end
-
- def min(&block)
- val = self.first
- last = self.last
-
- # numerics are special
- if (val.kind_of?(Fixnum) || val.kind_of?(Float)) && (last.kind_of?(Fixnum) || last.kind_of?(Float))
- return nil if val > last
- return nil if val == last && exclude_end?
-
- min = val
- if block && block.call(val, last) > 0
- min = last
- min -= 1 if exclude_end?
- end
- return min
- end
-
- min = nil
- each do |item|
- min =
- if min.nil?
- item
- elsif block && block.call(min, item) < 0
- item
- elsif item < min
- item
- else
- min
- end
- end
- min
- end
end

MODIFY
test/t/range.rb
test/t/range.rb
@@ -110,45 +110,3 @@ assert('Range#dup') do
assert_equal r.end, "z"
assert_true r.exclude_end?
end
-
-assert('Range#max') do
- assert_equal 10, (1..10).max
- assert_equal 9, (1...10).max
- assert_equal nil, (10..1).max
- assert_equal nil, (10...1).max
-
- # equal endpoints
- assert_equal 5, (5..5).max
- assert_equal nil, (5...5).max
-
- # block overrides comparison
- assert_equal(10, (1..10).max { |a, b| a <=> b })
- assert_equal(9, (1...10).max { |a, b| a <=> b })
- assert_equal(nil, (10..1).max { |a, b| a <=> b })
- assert_equal(nil, (10...1).max { |a, b| a <=> b })
- assert_equal(1, (1..10).max { |a, b| b <=> a })
- assert_equal(1, (1...10).max { |a, b| b <=> a })
- assert_equal(nil, (10..1).max { |a, b| b <=> a })
- assert_equal(nil, (10...1).max { |a, b| b <=> a })
-end
-
-assert('Range#min') do
- assert_equal 1, (1..10).min
- assert_equal 1, (1...10).min
- assert_equal nil, (10..1).min
- assert_equal nil, (10...1).min
-
- # equal endpoints
- assert_equal 7, (7..7).min
- assert_equal nil, (7...7).min
-
- # block overrides comparison
- assert_equal(1, (1..10).min { |a, b| a <=> b })
- assert_equal(1, (1...10).min { |a, b| a <=> b })
- assert_equal(nil, (10..1).min { |a, b| a <=> b })
- assert_equal(nil, (10...1).min { |a, b| a <=> b })
- assert_equal(10, (1..10).min { |a, b| b <=> a })
- assert_equal(9, (1...10).min { |a, b| b <=> a })
- assert_equal(nil, (10..1).min { |a, b| b <=> a })
- assert_equal(nil, (10...1).min { |a, b| b <=> a })
-end

Remove attempt at spec-compliant Range#max and Range#min from core