diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-10-15 18:35:53 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-10-15 18:35:53 +0900 |
| commit | 4b5dd5683b666526e216c150b5f36423ac80bcea (patch) | |
| tree | d4175aeefd1bf78893e21dda70615127594ad29f /mrbgems/mruby-range-ext/mrblib | |
| parent | c779413df39ef7d96583bda08104491c55049fad (diff) | |
| parent | 6b457d2c006c333bfdc1328ecc73db7e63a6aca5 (diff) | |
| download | mruby-4b5dd5683b666526e216c150b5f36423ac80bcea.tar.gz mruby-4b5dd5683b666526e216c150b5f36423ac80bcea.zip | |
Merge branch 'zubycz-work_for_merge'
Diffstat (limited to 'mrbgems/mruby-range-ext/mrblib')
| -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 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) |
