aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/visitors/visitor.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/visitors/visitor.rb')
-rw-r--r--lib/arel/visitors/visitor.rb20
1 files changed, 6 insertions, 14 deletions
diff --git a/lib/arel/visitors/visitor.rb b/lib/arel/visitors/visitor.rb
index 2152da9f05..bfe7342f04 100644
--- a/lib/arel/visitors/visitor.rb
+++ b/lib/arel/visitors/visitor.rb
@@ -12,17 +12,9 @@ module Arel
private
def self.dispatch_cache
- dispatch = Hash.new do |hash, class_name|
- hash[class_name] = "visit_#{(class_name || '').gsub('::', '_')}"
+ Hash.new do |hash, klass|
+ hash[klass] = "visit_#{(klass.name || '').gsub('::', '_')}"
end
-
- # pre-populate cache. FIXME: this should be passed in to each
- # instance, but we can do that later.
- self.class.private_instance_methods.sort.each do |name|
- next unless name =~ /^visit_(.*)$/
- dispatch[$1.gsub('_', '::')] = name
- end
- dispatch
end
def get_dispatch_cache
@@ -34,14 +26,14 @@ module Arel
end
def visit object
- send dispatch[object.class.name], object
+ send dispatch[object.class], object
rescue NoMethodError => e
- raise e if respond_to?(dispatch[object.class.name], true)
+ raise e if respond_to?(dispatch[object.class], true)
superklass = object.class.ancestors.find { |klass|
- respond_to?(dispatch[klass.name], true)
+ respond_to?(dispatch[klass], true)
}
raise(TypeError, "Cannot visit #{object.class}") unless superklass
- dispatch[object.class.name] = dispatch[superklass.name]
+ dispatch[object.class] = dispatch[superklass]
retry
end
end