Module: RubyDecorators
- Defined in:
- lib/ruby_decorators.rb,
lib/ruby_decorators/version.rb
Defined Under Namespace
Classes: Stack
Constant Summary collapse
- VERSION =
"0.0.3"
Instance Method Summary collapse
Instance Method Details
#method_added(method_name) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_decorators.rb', line 11 def method_added(method_name) super @methods ||= {} @decorators ||= {} return if RubyDecorators::Stack.all.empty? @methods[method_name] = instance_method(method_name) @decorators[method_name] = RubyDecorators::Stack.all.pop(42) class_eval " \#{method_visibility_for(method_name)}\n def \#{method_name}(*args, &blk)\n decorators = self.class.instance_variable_get(:@decorators)[:\#{method_name}]\n method = self.class.instance_variable_get(:@methods)[:\#{method_name}]\n\n decorators.inject(method.bind(self)) do |method, decorator|\n decorator = decorator.new if decorator.respond_to?(:new)\n lambda { |*a, &b| decorator.call(method, *a, &b) }\n end.call(*args, &blk)\n end\n RUBY_EVAL\nend\n", __FILE__, __LINE__ + 1 |