Created
April 12, 2012 08:22
-
-
Save dgtm/2365598 to your computer and use it in GitHub Desktop.
Alias Method
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
class Animal | |
class << self | |
def query | |
where(name: "cat") | |
end | |
def query_as_array | |
criteria = send("query_as_criteria") | |
criteria.count == 0 ? nil : criteria.to_a | |
end | |
alias_method :query_as_criteria, :query | |
alias_method :query, :query_as_array | |
end | |
end | |
Animal.query # now returns an array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment