summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-range-ext/mrblib/range.rb
diff options
context:
space:
mode:
Diffstat (limited to 'mrbgems/mruby-range-ext/mrblib/range.rb')
-rw-r--r--mrbgems/mruby-range-ext/mrblib/range.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/mrbgems/mruby-range-ext/mrblib/range.rb b/mrbgems/mruby-range-ext/mrblib/range.rb
index fadddc343..018bd7094 100644
--- a/mrbgems/mruby-range-ext/mrblib/range.rb
+++ b/mrbgems/mruby-range-ext/mrblib/range.rb
@@ -27,10 +27,12 @@ class Range
end
def max(&block)
- val = self.first
- last = self.last
+ val = self.begin
+ last = self.end
return super if block
+ raise RangeError, "cannot get the maximum of endless range" if last.nil?
+
# fast path for numerics
if val.kind_of?(Numeric) && last.kind_of?(Numeric)
raise TypeError if exclude_end? && !last.kind_of?(Integer)
@@ -47,9 +49,13 @@ class Range
end
def min(&block)
- val = self.first
- last = self.last
- return super if block
+ val = self.begin
+ last = self.end
+ if block
+ raise RangeError, "cannot get the minimum of endless range with custom comparison method" if last.nil?
+ return super
+ end
+ return val if last.nil?
# fast path for numerics
if val.kind_of?(Numeric) && last.kind_of?(Numeric)