How can I enumerate a property in an array of objects, modify it, and join them in a string? I know there must be Ruby features that make this easier, but I have been having trouble understanding them.
How can I accomplish this more efficiently (less code/easier to read)?
arr = Array.new
|obj| arr.push(obj.someProp + '-addThisStr')
puts arr.sort.uniq.join(', ')
You basically have it but you can skip the
result = someArrayOfObjects.map do |obj| obj.someProp + '-addThisStr' end.sort.uniq.join(", ") puts result