Like a Enumerable#take

This commit is contained in:
ksss
2016-11-25 22:20:33 +09:00
parent 743c1e7be1
commit c28a963bf4
+9 -6
View File
@@ -222,14 +222,17 @@ module Enumerable
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