From ed75a6d948a12fae73430e3df59d226263f5bf6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=BCtke?= Date: Thu, 8 May 2008 17:22:07 -0400 Subject: [PATCH] Make before_method work more like method_missing --- lib/liquid/drop.rb | 10 ++++++---- test/drop_test.rb | 11 +++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/liquid/drop.rb b/lib/liquid/drop.rb index 7a2719e..7b531b5 100644 --- a/lib/liquid/drop.rb +++ b/lib/liquid/drop.rb @@ -28,10 +28,12 @@ module Liquid end # 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 + def invoke_drop(method) + if self.class.public_instance_methods.include?(method.to_s) + send(method.to_sym) + else + before_method(method) + end end def has_key?(name) diff --git a/test/drop_test.rb b/test/drop_test.rb index 0b4b1e2..78a2f73 100644 --- a/test/drop_test.rb +++ b/test/drop_test.rb @@ -62,13 +62,16 @@ class ProductDrop < Liquid::Drop end class EnumerableDrop < Liquid::Drop - include Enumerable + + def size + 3 + end def each yield 1 yield 2 yield 3 - end + end end @@ -147,6 +150,10 @@ class DropsTest < Test::Unit::TestCase def test_enumerable_drop 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