diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-10-15 18:35:13 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-10-15 18:35:13 +0900 |
| commit | 6b457d2c006c333bfdc1328ecc73db7e63a6aca5 (patch) | |
| tree | d4175aeefd1bf78893e21dda70615127594ad29f /mrbgems/mruby-range-ext/mrblib/range.rb | |
| parent | c779413df39ef7d96583bda08104491c55049fad (diff) | |
| parent | bec4d053400c3a11c8efd68c3e8bd5ea4a0bcc54 (diff) | |
| download | mruby-6b457d2c006c333bfdc1328ecc73db7e63a6aca5.tar.gz mruby-6b457d2c006c333bfdc1328ecc73db7e63a6aca5.zip | |
Merge branch 'work_for_merge' of https://github.com/zubycz/mruby into zubycz-work_for_merge
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 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) |
