Skip to content

Instantly share code, notes, and snippets.

@krisleech
Last active October 12, 2018 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisleech/6ba4fbcb4303e0d588ace9f1bd53cc6a to your computer and use it in GitHub Desktop.
Save krisleech/6ba4fbcb4303e0d588ace9f1bd53cc6a to your computer and use it in GitHub Desktop.
Ruby snippets

ActiveRecord SQL queries in stdout, good for specs or console:

require 'active_record'
ActiveRecord::Base.logger = Logger.new(STDOUT)

Hashes are destructured when using keyword arguments

def foo(a:, b:)
  puts a.to_s + b.to_s
end

foo(1,2)
foo(a: 1, b: 2)

Hash values to vars

id, name = { id: 1, name: 'Foo', amount: 3 }.values_at(:id, :name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment