Created
March 2, 2011 02:25
-
-
Save stakes/850350 to your computer and use it in GitHub Desktop.
More efficient?
This file contains 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
# Creates finders | |
def serialized_finder(serialized, accessors) | |
accessors.keys.each do |k| | |
method_name = "find_by_#{k}" | |
define_singleton_method(method_name) do |val=nil| | |
a = [] | |
a << self.all.select { |s| | |
s[serialized][k] == val | |
} | |
a unless a.empty? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment