I have an array of objects, like so:
[
#<name: "value1", field: "field_A">,
#<name: "value2", field: "field_B">,
#<name: "value3", field: "field_C">
]
I want as output:
"value1 value2 value3"
What I am currently doing:
variable = ''
array.each { |x| variable << x.name << ' ' }
This is ugly, and also leaves an extra space on the end. I thing Array::join is where I am looking to go, but I can’t find a way to access the object fields from it. Is there another method similar to join that I should be using, or is there another more sensible approach?
Any suggestions would be appreciated.
1 Answer