Make before_method work more like method_missing

This commit is contained in:
Tobias Lütke
2008-05-08 17:22:07 -04:00
parent 63f9a05223
commit ed75a6d948
2 changed files with 15 additions and 6 deletions
+5 -3
View File
@@ -29,9 +29,11 @@ module Liquid
# called by liquid to invoke a drop
def invoke_drop(method)
result = before_method(method)
result ||= send(method.to_sym) if self.class.public_instance_methods.include?(method.to_s)
result
if self.class.public_instance_methods.include?(method.to_s)
send(method.to_sym)
else
before_method(method)
end
end
def has_key?(name)
+8 -1
View File
@@ -62,7 +62,10 @@ class ProductDrop < Liquid::Drop
end
class EnumerableDrop < Liquid::Drop
include Enumerable
def size
3
end
def each
yield 1
@@ -148,6 +151,10 @@ class DropsTest < Test::Unit::TestCase
assert_equal '123', Liquid::Template.parse( '{% for c in collection %}{{c}}{% endfor %}').render('collection' => EnumerableDrop.new)
end
def test_enumerable_drop_size
assert_equal '3', Liquid::Template.parse( '{{collection.size}}').render('collection' => EnumerableDrop.new)
end
end