Skip to content
This repository

Fix Range#max behavior in 1.9 mode with inclusive ranges #2109

Merged
merged 2 commits into from over 1 year ago

3 participants

Ryan Fitzgerald Jesse Cooke Kenichi Kamiya
Ryan Fitzgerald

This rolls back a change made in 04c2c40. If a range is inclusive and the start and end points are equal, Range#max should return the endpoint, not nil.

added some commits December 28, 2012
Ryan Fitzgerald Add specs to Range#max and Range#min
The one that fails under 1.9 mode is "(5..5).max.should equal(5)".
4b483c2
Ryan Fitzgerald Fix Range#max behavior in 1.9 mode
This rolls back a change made in 04c2c40d. If a range is inclusive and
the start and end points are the same, Range#max should return the
endpoint, not nil.
f589a54
Jesse Cooke jc00ke merged commit 0dca65d into from December 28, 2012
Jesse Cooke jc00ke closed this December 28, 2012
Jesse Cooke
Collaborator

Travis timeout was in 1.8 mode. :cry:

Ryan Fitzgerald rf- deleted the branch December 28, 2012
Kenichi Kamiya
Collaborator

@rf- I'm sorry to trouble you. And thanks for the fix :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Dec 28, 2012
Ryan Fitzgerald Add specs to Range#max and Range#min
The one that fails under 1.9 mode is "(5..5).max.should equal(5)".
4b483c2
Ryan Fitzgerald Fix Range#max behavior in 1.9 mode
This rolls back a change made in 04c2c40d. If a range is inclusive and
the start and end points are the same, Range#max should return the
endpoint, not nil.
f589a54
This page is out of date. Refresh to see the latest.
2  kernel/common/range19.rb
@@ -13,7 +13,7 @@ def first(n=undefined)
13 13
 
14 14
   def max(&block)
15 15
     return super(&block) if block_given? || (@excl && !@end.kind_of?(Numeric))
16  
-    return nil unless @end > @begin
  16
+    return nil if @end < @begin || (@excl && @end == @begin)
17 17
 
18 18
     if @excl
19 19
       unless @end.kind_of?(Integer)
7  spec/ruby/core/range/max_spec.rb
@@ -28,9 +28,16 @@
28 28
     it "returns nil when the endpoint is less than the start point" do
29 29
       (100..10).max.should be_nil
30 30
       ('z'..'l').max.should be_nil
  31
+    end
  32
+
  33
+    it "returns nil when the endpoint equals the start point and the range is exclusive" do
31 34
       (5...5).max.should be_nil
32 35
     end
33 36
 
  37
+    it "returns the endpoint when the endpoint equals the start point and the range is inclusive" do
  38
+      (5..5).max.should equal(5)
  39
+    end
  40
+
34 41
     ruby_version_is "1.9" do
35 42
       it "returns nil when the endpoint is less than the start point in a Float range" do
36 43
         (3003.20..908.1111).max.should be_nil
7  spec/ruby/core/range/min_spec.rb
@@ -22,9 +22,16 @@
22 22
     it "returns nil when the start point is greater than the endpoint" do
23 23
       (100..10).min.should be_nil
24 24
       ('z'..'l').min.should be_nil
  25
+    end
  26
+
  27
+    it "returns nil when the endpoint equals the start point and the range is exclusive" do
25 28
       (7...7).min.should be_nil
26 29
     end
27 30
 
  31
+    it "returns the start point when the endpoint equals the start point and the range is inclusive" do
  32
+      (7..7).min.should equal(7)
  33
+    end
  34
+
28 35
     ruby_version_is "1.9" do
29 36
       it "returns nil when the start point is greater than the endpoint in a Float range" do
30 37
         (3003.20..908.1111).min.should be_nil
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.