I've got an array of hashes: hashes = [{field: 'one'}, {field: 'two'}]
And I want to get the list of fields from it: ['one', 'two']
hashes.map(&:field) doesn't work, clearly, and hashes.map { |hash| hash[field] } feels a bit clunky to me.
Is there a more elegant way?
EDIT: I should clarify, I do only want the value of 'fields' in my response.
So, hashes = [{field: 'one', another: 'three'}, {field: 'two'}].do_the_thing should be ['one', 'two']
hashes.collect-collectis analiiasformapand fits here - collecting the fields from each hash.hashes.map { |hash| hash[:field] }is not just OK, it's the perfect way to do this. Note you wrotehash[field]; you need:field.