Permalink
Browse files

Like a Enumerable#take

  • Loading branch information...
ksss committed Nov 25, 2016
1 parent 743c1e7 commit c28a963bf426afb00f2ebb32c0dff65dd3ff4b3f
Showing with 9 additions and 6 deletions.
  1. +9 −6 mrbgems/mruby-enum-ext/mrblib/enum.rb
@@ -222,14 +222,17 @@ def first(n=NONE)
end
return nil
else
a = []
i = 0
raise TypeError, "no implicit conversion of #{n.class} into Integer" unless n.respond_to?(: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 n<=i
a.push val.__svalue
i += 1
ary << val.__svalue
i -= 1
break if i == 0
end
a
ary
end
end

0 comments on commit c28a963

Please sign in to comment.