Today I Learned

A collection of useful bits & bobs I'd rather not forget
Copying Rails console output to clipboard on Mac

From time to time I want to work with information which is from rails console output outside of the command line. Helpfully, ruby provides a neat way to pipe console output into the mac system clipboard using IO:

IO.popen("pbcopy", "w") do |pipe| 
  # Get users without subscriptions as CSV and add them to the clipboard
  pipe.puts User.includes(:subscription).where(subscriptions: {user_id: nil}).pluck(:email).to_csv
end
RUBY
RAILS
Things I learned on other days →