Rahul Singh Rahul Singh - 2 months ago 8x
Ruby Question

how to pluck email from array of users?

If I do

then it works fine.

But if I do

arr = Array.new
arr = User.all

and then


this gives me following error

undefined method `pluck' for #<Array:0x007f4ff8daf3c8>

which means I cannot use pluck with arrays, so how can we extract particular fields values from an array of records in just one line like above.
I don't want to loop through each reocrd in array.


pluck is useful to do a minimalist db query.

When you have an array, just use map: