Skip to content

Commit

Permalink
Shouldn't call each method if size is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
ksss committed Nov 24, 2016
1 parent 9e2faec commit 5134734
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mrbgems/mruby-enum-ext/mrblib/enum.rb
Expand Up @@ -61,9 +61,11 @@ def take(n)
i = n.to_int i = n.to_int
raise ArgumentError, "attempt to take negative size" if i < 0 raise ArgumentError, "attempt to take negative size" if i < 0
ary = [] ary = []
return ary if i == 0
self.each do |*val| self.each do |*val|
break if ary.size >= n
ary << val.__svalue ary << val.__svalue
i -= 1
break if i == 0
end end
ary ary
end end
Expand Down

0 comments on commit 5134734

Please sign in to comment.