Make logic in Context#lookup_and_evaluate more understandable

This commit is contained in:
Justin Li
2016-02-02 23:22:46 -05:00
parent 5a50c12953
commit 0cc8b68a97

View File

@@ -205,10 +205,14 @@ module Liquid
end
def lookup_and_evaluate(obj, key)
if (value = obj[key]).is_a?(Proc) && obj.respond_to?(:[]=)
obj[key] = (value.arity == 0) ? value.call : value.call(self)
elsif strict_variables && obj.respond_to?(:key?) && !obj.key?(key)
if @strict_variables && obj.respond_to?(:key?) && !obj.key?(key)
raise Liquid::UndefinedVariable, "undefined variable #{key}"
end
value = obj[key]
if value.is_a?(Proc) && obj.respond_to?(:[]=)
obj[key] = (value.arity == 0) ? value.call : value.call(self)
else
value
end