Created
August 26, 2011 17:55
-
-
Save ernie/1173973 to your computer and use it in GitHub Desktop.
:to_ary fun
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
# If you put a DSL stub object like this inside an array and call array#flatten without | |
# being sure to call super on :to_ary, you get fun stuff like this: | |
# can't convert Squeel::Nodes::Stub to Array | |
# (Squeel::Nodes::Stub#to_ary gives Squeel::Nodes::KeyPath) | |
def method_missing(method_id, *args) | |
super if method_id == :to_ary | |
if args.empty? | |
KeyPath.new(self, method_id) | |
elsif (args.size == 1) && (Class === args[0]) | |
KeyPath.new(self, Join.new(method_id, Arel::InnerJoin, args[0])) | |
else | |
KeyPath.new(self, Nodes::Function.new(method_id, args)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment