Keith Schacht’s Weblog

Subscribe

💡 TIL: pick is the single-value version of pluck in Rails

26th November 2024

Instead of doing

Messages.pluck(:user_id).first
you can do
Messages.pick(:user_id)

More recent articles

This is pick is the single-value version of pluck in Rails by Keith Schacht, posted on 26th November 2024.

Part of series Today I Learned

  1. Rails migrations can include an up_only part - Oct. 29, 2024, 8:29 p.m.
  2. NASA's Dragonfly probe to Saturn's Titan in 2028 - Nov. 26, 2024, 2:58 p.m.
  3. Rails ActiveRecord has a .sole method - Nov. 26, 2024, 11:15 p.m.
  4. pick is the single-value version of pluck in Rails - Nov. 26, 2024, 11:24 p.m.
  5. Elegant solution to versioning an API - Feb. 24, 2025, 3:13 p.m.
  6. Regex within string square brackets - Feb. 24, 2025, 3:16 p.m.
  7. Ruby's clamp method reduces conditionals - Feb. 24, 2025, 3:19 p.m.

Next: Elegant solution to versioning an API

Previous: Rails ActiveRecord has a .sole method