Skip to content
Browse files

Merge pull request #1329 from jtdowney/range-fixes

Specs for Range#min and Range#max behavior on 1.8 and patch for 1.9
  • Loading branch information...
2 parents a81da70 + 9bc0625 commit 5a9984ba850111e73f0b44597b9df6d48043dde8 @rue rue committed Oct 22, 2011
View
7 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
View
12 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
View
6 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
View
6 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
View
2 spec/tags/19/ruby/core/range/max_tags.txt
@@ -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
View
2 spec/tags/19/ruby/core/range/min_tags.txt
@@ -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
View
0 spec/tags/19/ruby/core/range/step_tags.txt
No changes.

0 comments on commit 5a9984b

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