Search code examples
rubylistiteratorenumerable

How can I get a list from a Ruby enumerable?


I know of Python's list method that can consume all elements from a generator. Is there something like that available in Ruby?

I know of :

elements = []
enumerable.each {|i| elements << i}

I also know of the inject alternative. Is there some ready available method?


Solution

  • Enumerable#to_a