Skip to content

Instantly share code, notes, and snippets.

@ernie
Created August 26, 2011 17:55
Show Gist options
  • Save ernie/1173973 to your computer and use it in GitHub Desktop.
Save ernie/1173973 to your computer and use it in GitHub Desktop.
:to_ary fun
# 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