This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |