Is there a better way for
result = []
function_that_yields{ |value| result << value }
Is there a better way for
result = []
function_that_yields{ |value| result << value }
If the function that yields has no logic to build the array, then this is the only way to accomplish this task. Otherwise, consider using built-in enumerable methods such as inject or map.
Yeah, you can use result = something.inject([]) {|x,y| x << y}
You can push anything into x, so you could do something like x << value in this case.