Skip to content

Instantly share code, notes, and snippets.

@imme5150
imme5150 / any_of.rb
Last active January 3, 2016 00:19 — forked from oelmekki/any_of.rb
# Add this to an initializer file to extend ActiveRecord
# You can pass in an array of hashes. The key/values of your hashes will be joined w/ ANDs
# The hashes in the array will be joined w/ ORs
# You can also pass in an array of strings or arrays
class ActiveRecord::Base
def self.any_of( queries )
queries = queries.map do |query|
query = where( query ) if [ String, Hash ].any? { |type| query.kind_of? type }
query = where( *query ) if query.kind_of?( Array )
@imme5150
imme5150 / gist:6083600
Last active December 20, 2015 06:09 — forked from 1o1brian/gist:2919347
# thanks to railscasts:
# http://railscasts.com/episodes/48-console-tricks-revised?view=comments
# add this to your ~/.irbrc file
class Object
# look up source location of a method
def sl(method_name)
self.method(method_name).source_location