I’m new to Ruby, how do I do something like this? in C#, I would have written
my_block().ToList()
and it would work.
I’m imagining this function
def my_block
yield 1
yield 2
yield 3
end
my_block.to_enum().map {|a| a}
This gives me this error:
test.rb:2:in `my_block': no block given (yield) (LocalJumpError)
from test.rb:7:in `<main>'
What is the correct incantation for this behavior?
The correct syntax for your code is:
Object#to_enum expects symbol with method name as its parameter:
Equivalent for C#
ToList()is Enumerable#to_a