Skip to content
Browse files

The decorator should get the original method as an argument, instead …

…of its return value
  • Loading branch information...
1 parent 76f7a68 commit d3d6e2de5614a2ec505000db90d4d2db444a0343 @fredwu committed Sep 12, 2012
Showing with 10 additions and 10 deletions.
  1. +4 −4 README.md
  2. +2 −2 lib/ruby_decorators.rb
  3. +4 −4 spec/ruby_decorators_spec.rb
View
8 README.md
@@ -20,8 +20,8 @@ Or install it yourself as:
```ruby
class Batman < RubyDecorator
- def call(this)
- this.sub('world', 'batman')
+ def call(this, *args, &blk)
+ this.call(*args, &blk).sub('world', 'batman')
end
end
@@ -30,8 +30,8 @@ class Catwoman < RubyDecorator
@args = args.any? ? args : ['catwoman']
end
- def call(this)
- this.sub('world', @args.join(' '))
+ def call(this, *args, &blk)
+ this.call(*args, &blk).sub('world', @args.join(' '))
end
end
View
4 lib/ruby_decorators.rb
@@ -25,9 +25,9 @@ def #{method_name}(*args, &blk)
decorator ||= self.class.instance_variable_get(:@__decorators)["#{method_name}"]
if args.any?
- decorator.call(self.send :__undecorated_#{method_name}, *args, &blk)
+ decorator.call(method(:__undecorated_#{method_name}), *args, &blk)
else
- decorator.call(self.send :__undecorated_#{method_name}, &blk)
+ decorator.call(method(:__undecorated_#{method_name}), &blk)
end
end
RUBY_EVAL
View
8 spec/ruby_decorators_spec.rb
@@ -8,8 +8,8 @@ def call(this)
end
class Batman < RubyDecorator
- def call(this)
- this.sub('world', 'batman')
+ def call(this, *args, &blk)
+ this.call(*args, &blk).sub('world', 'batman')
end
end
@@ -18,8 +18,8 @@ def initialize(*args)
@args = args.any? ? args : ['catwoman']
end
- def call(this)
- this.sub('world', @args.join(' '))
+ def call(this, *args, &blk)
+ this.call(*args, &blk).sub('world', @args.join(' '))
end
end

0 comments on commit d3d6e2d

Please sign in to comment.
Something went wrong with that request. Please try again.