What is the difference between select,pluck,map and collect?

Hello friends, 


I am going to show you what exactly difference between all this keywords.


Below screen shot i have 3 different user record, which we are getting with all this queries.



1) User.all.select(:email)

select takes (0.3ms) when find user by email and returns Active record object.

2) User.all.pluck(:email)
pluck also takes (0.3ms) when find user by email and returns email Array.

3) User.all.collect(&:email)
collect takes (0.4ms) when find user by email and returns email Array.

4) User.all.map(&:email)

 map takes (0.5ms) when find user by email and returns email Array.


You can also try it on your rails console.

Leave a comment