Change Drop method lookup to not hit respond_to?

Class.public_method_defined? ends up diving into Ruby's core looking for
a method with the given method_or_key. This process at some point turns
method_or_key into a Symbol. This change no longer takes that path and
thus doesn't grow the Symbol table.
This commit is contained in:
Jason Roelofs
2013-01-16 11:07:48 -05:00
parent 7bcb565668
commit a48e162237
+8 -1
View File
@@ -31,7 +31,7 @@ module Liquid
# called by liquid to invoke a drop
def invoke_drop(method_or_key)
if method_or_key && method_or_key != EMPTY_STRING && self.class.public_method_defined?(method_or_key.to_s)
if method_or_key && method_or_key != EMPTY_STRING && drop_method_defined?(method_or_key.to_s)
send(method_or_key.to_s)
else
before_method(method_or_key)
@@ -47,5 +47,12 @@ module Liquid
end
alias :[] :invoke_drop
private
# Check for method existence without invoking respond_to?, which creates symbols
def drop_method_defined?(method_name)
self.class.public_instance_methods.any? {|method| method.to_s == method_name }
end
end
end