diff options
| author | taiyoslime <[email protected]> | 2020-10-05 19:53:05 +0900 |
|---|---|---|
| committer | taiyoslime <[email protected]> | 2020-10-13 14:09:36 +0900 |
| commit | bec4d053400c3a11c8efd68c3e8bd5ea4a0bcc54 (patch) | |
| tree | 166195f4009b90a90d1fe1b28ad4c8c84ba2597d /mrbgems/mruby-range-ext/mrblib/range.rb | |
| parent | 9ea7b718683386d2dc0787e919fc3d413ab20e67 (diff) | |
| download | mruby-bec4d053400c3a11c8efd68c3e8bd5ea4a0bcc54.tar.gz mruby-bec4d053400c3a11c8efd68c3e8bd5ea4a0bcc54.zip | |
Introduce endless range (a part of #5085)
Co-Authored-By: n4o847 <[email protected]>
Co-Authored-By: smallkirby <[email protected]>
Diffstat (limited to 'mrbgems/mruby-range-ext/mrblib/range.rb')
| -rw-r--r-- | mrbgems/mruby-range-ext/mrblib/range.rb | 16 |
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 a213beb57..8b0969003 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?(Fixnum) @@ -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) |
