diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-11-24 11:31:28 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2016-11-24 11:31:28 +0900 |
| commit | cef7bd5416a2c477c48aa99a61427008ea1dc491 (patch) | |
| tree | bcdb63838016d174bac38e8580c364ccbb287cb7 | |
| parent | 227daa881137d5251e03eea0883b9b574a1f064e (diff) | |
| parent | 5134734541dd993f74a40b1621009add2cf110bf (diff) | |
| download | mruby-cef7bd5416a2c477c48aa99a61427008ea1dc491.tar.gz mruby-cef7bd5416a2c477c48aa99a61427008ea1dc491.zip | |
Merge pull request #3271 from ksss/enum-take
Fix Enumeable#take some incompatibility
| -rw-r--r-- | mrbgems/mruby-enum-ext/mrblib/enum.rb | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/mrbgems/mruby-enum-ext/mrblib/enum.rb b/mrbgems/mruby-enum-ext/mrblib/enum.rb index 6724dff37..5b50aba00 100644 --- a/mrbgems/mruby-enum-ext/mrblib/enum.rb +++ b/mrbgems/mruby-enum-ext/mrblib/enum.rb @@ -58,13 +58,14 @@ module Enumerable def take(n) raise TypeError, "no implicit conversion of #{n.class} into Integer" unless n.respond_to?(:to_int) - raise ArgumentError, "attempt to take negative size" if n < 0 - - n = n.to_int + i = n.to_int + raise ArgumentError, "attempt to take negative size" if i < 0 ary = [] + return ary if i == 0 self.each do |*val| - break if ary.size >= n ary << val.__svalue + i -= 1 + break if i == 0 end ary end |
