From 785ed1c12670fcc3d39f16f5ec391894ff457f34 Mon Sep 17 00:00:00 2001 From: John Downey Date: Fri, 21 Oct 2011 22:51:08 -0400 Subject: [PATCH 1/2] Added specs for 1.8 behavior of Range#min and Range#max --- spec/ruby/core/range/max_spec.rb | 6 ++++++ spec/ruby/core/range/min_spec.rb | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/spec/ruby/core/range/max_spec.rb b/spec/ruby/core/range/max_spec.rb index 9297eb23cd..f6263b8562 100644 --- a/spec/ruby/core/range/max_spec.rb +++ b/spec/ruby/core/range/max_spec.rb @@ -13,6 +13,12 @@ end end + ruby_version_is ""..."1.9" do + it "raises TypeError when called on a Float range" do + lambda { (303.20..908.1111).max }.should raise_error(TypeError) + end + end + it "returns nil when the endpoint is less than the start point" do (100..10).max.should be_nil ('z'..'l').max.should be_nil diff --git a/spec/ruby/core/range/min_spec.rb b/spec/ruby/core/range/min_spec.rb index 9890f9157d..371c089235 100644 --- a/spec/ruby/core/range/min_spec.rb +++ b/spec/ruby/core/range/min_spec.rb @@ -13,6 +13,12 @@ end end + ruby_version_is ""..."1.9" do + it "raises TypeError when called on a Float range" do + lambda { (303.20..908.1111).min }.should raise_error(TypeError) + end + end + it "returns nil when the start point is greater than the endpoint" do (100..10).min.should be_nil ('z'..'l').min.should be_nil From 9bc06256093e216aeadefd5bed03fb63657588b7 Mon Sep 17 00:00:00 2001 From: John Downey Date: Fri, 21 Oct 2011 22:52:33 -0400 Subject: [PATCH 2/2] Patched Range#min and Range#max for 1.9 --- kernel/common/range.rb | 7 ------- kernel/common/range19.rb | 12 ++++++++++++ spec/tags/19/ruby/core/range/max_tags.txt | 2 -- spec/tags/19/ruby/core/range/min_tags.txt | 2 -- spec/tags/19/ruby/core/range/step_tags.txt | 0 5 files changed, 12 insertions(+), 11 deletions(-) delete mode 100644 spec/tags/19/ruby/core/range/max_tags.txt delete mode 100644 spec/tags/19/ruby/core/range/min_tags.txt delete mode 100644 spec/tags/19/ruby/core/range/step_tags.txt diff --git a/kernel/common/range.rb b/kernel/common/range.rb index eccebfbf89..b0ecc9adec 100644 --- a/kernel/common/range.rb +++ b/kernel/common/range.rb @@ -322,12 +322,5 @@ def to_a super end - - def max &a - return super(&a) if block_given? - return nil if @end < @begin - @end - end - end diff --git a/kernel/common/range19.rb b/kernel/common/range19.rb index 93bff176ef..129b4c6d85 100644 --- a/kernel/common/range19.rb +++ b/kernel/common/range19.rb @@ -1,3 +1,15 @@ class Range alias_method :cover?, :=== + + def max(&block) + return super(&block) if block_given? + return nil if @end < @begin + @end + end + + def min(&block) + return super(&block) if block_given? + return nil if @end < @begin + @begin + end end diff --git a/spec/tags/19/ruby/core/range/max_tags.txt b/spec/tags/19/ruby/core/range/max_tags.txt deleted file mode 100644 index 7692f69479..0000000000 --- a/spec/tags/19/ruby/core/range/max_tags.txt +++ /dev/null @@ -1,2 +0,0 @@ -fails:Range#max returns the maximum value in the Float range when called with no arguments -fails:Range#max returns nil when the endpoint is less than the start point in a Float range diff --git a/spec/tags/19/ruby/core/range/min_tags.txt b/spec/tags/19/ruby/core/range/min_tags.txt deleted file mode 100644 index 199aecaee4..0000000000 --- a/spec/tags/19/ruby/core/range/min_tags.txt +++ /dev/null @@ -1,2 +0,0 @@ -fails:Range#min returns the minimum value in the Float range when called with no arguments -fails:Range#min returns nil when the start point is greater than the endpoint in a Float range diff --git a/spec/tags/19/ruby/core/range/step_tags.txt b/spec/tags/19/ruby/core/range/step_tags.txt deleted file mode 100644 index e69de29bb2..0000000000