Skip to content

Instantly share code, notes, and snippets.

@stakes
Created March 2, 2011 02:25
Show Gist options
  • Save stakes/850350 to your computer and use it in GitHub Desktop.
Save stakes/850350 to your computer and use it in GitHub Desktop.
More efficient?
# 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