diff options
author | Mike Dalessio <mike@csa.net> | 2010-09-16 11:49:34 -0400 |
---|---|---|
committer | Mike Dalessio <mike@csa.net> | 2010-09-16 11:49:34 -0400 |
commit | 6b8a382a75d1425ecf978f1e0fe9a636d55c8cc0 (patch) | |
tree | 3d0ba7e847e7f702eca646a6c7ebba983288af13 /lib/arel | |
parent | f95f0918d745856080c06b5e3ae5c323b2de43d2 (diff) | |
download | rails-6b8a382a75d1425ecf978f1e0fe9a636d55c8cc0.tar.gz rails-6b8a382a75d1425ecf978f1e0fe9a636d55c8cc0.tar.bz2 rails-6b8a382a75d1425ecf978f1e0fe9a636d55c8cc0.zip |
using a Hash with default proc to memoize dispatch methods
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 5be95565f3..e8b63a1533 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -222,17 +222,12 @@ module Arel def visit_BigDecimal o; quote(o) end def visit_FalseClass o; quote(o) end - DISPATCH = {} - def visit object - send "visit_#{object.class.name.gsub('::', '_')}", object - #send DISPATCH[object.class], object + DISPATCH = Hash.new do |hash, klass| + hash[klass] = "visit_#{klass.name.gsub('::', '_')}" end - private_instance_methods(false).each do |method| - method = method.to_s - next unless method =~ /^visit_(.*)$/ - const = $1.split('_').inject(Object) { |m,s| m.const_get s } - DISPATCH[const] = method + def visit object + send DISPATCH[object.class], object end def quote value, column = nil |