Class: Aop::MethodReference
- Inherits:
-
Object
- Object
- Aop::MethodReference
- Defined in:
- lib/aop/method_reference.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Singleton
Class Method Summary collapse
Instance Method Summary collapse
- #call(target, *args, &blk) ⇒ Object
- #decorate(target, &with) ⇒ Object
-
#initialize(m) ⇒ MethodReference
constructor
A new instance of MethodReference.
- #method_name ⇒ Object
Constructor Details
#initialize(m) ⇒ MethodReference
Returns a new instance of MethodReference.
8 9 10 |
# File 'lib/aop/method_reference.rb', line 8 def initialize(m) @name = m[1..-1] end |
Class Method Details
.from(m) ⇒ Object
3 4 5 6 |
# File 'lib/aop/method_reference.rb', line 3 def self.from(m) return new(m) if m[0...1] == "#" Singleton.new(m) end |
Instance Method Details
#call(target, *args, &blk) ⇒ Object
23 24 25 |
# File 'lib/aop/method_reference.rb', line 23 def call(target, *args, &blk) target.send(alias_name, *args, &blk) end |
#decorate(target, &with) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/aop/method_reference.rb', line 12 def decorate(target, &with) name = @name new_name = alias_name alias_target(target).class_eval do alias_method(new_name, name) define_method(name, &with) end rescue NameError => err raise PointcutNotFound.new(method_spec(target), err) end |
#method_name ⇒ Object
27 28 29 |
# File 'lib/aop/method_reference.rb', line 27 def method_name "#{method_notation}#{@name}" end |