Unverified Commit c28a963b authored by ksss's avatar ksss

Like a Enumerable#take

parent 743c1e7b
...@@ -222,14 +222,17 @@ module Enumerable ...@@ -222,14 +222,17 @@ module Enumerable
end end
return nil return nil
else else
a = [] raise TypeError, "no implicit conversion of #{n.class} into Integer" unless n.respond_to?(:to_int)
i = 0 i = n.to_int
raise ArgumentError, "attempt to take negative size" if i < 0
ary = []
return ary if i == 0
self.each do |*val| self.each do |*val|
break if n<=i ary << val.__svalue
a.push val.__svalue i -= 1
i += 1 break if i == 0
end end
a ary
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment