I just encounter this piece of code
Enumerator.new((1..100), :take, 5).to_a
# => []
Does anyone know why it returns an empty array and not an array of 5 integers?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
From the docs,
Enumerator#new:This second usage (which you should not use according to the documentation), needs a
each-like method (that’s it, one that yields values).takereturns values, but does not yield them, so you get an empty enumerable.Note that in Ruby 2 it will be plain simple to perform a lazy
take: