map vs pluck

Category:

Both methods return the same output (an array of strings).

Article.all.map{|a| a.title}
Article.pluck(:title)

But they do that in different ways.

SQL query generated by all:

SELECT "articles".* FROM "articles"

It fetches all atributes, then it converts the collection with map method.

SQL query generated by pluck (or .all.pluck):

SELECT "articles"."title" FROM "articles"

pluck is faster.