Class: MethodCallbacks::Method

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/method_callbacks/method.rb

Constant Summary collapse

ALIAS_PREFIX =
"__method_callback_alias_to_original"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Method

Returns a new instance of Method.



17
18
19
# File 'lib/method_callbacks/method.rb', line 17

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/method_callbacks/method.rb', line 12

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
# File 'lib/method_callbacks/method.rb', line 21

def ==(other)
  self.name == other.name
end

#aliasObject



25
26
27
# File 'lib/method_callbacks/method.rb', line 25

def alias
  "#{ALIAS_PREFIX}_#{name}"
end

#callbacks(type) ⇒ Object



29
30
31
32
# File 'lib/method_callbacks/method.rb', line 29

def callbacks(type)
  @_callbacks ||= {}
  @_callbacks[type] ||= []
end

#execute(type, object) ⇒ Object



34
35
36
# File 'lib/method_callbacks/method.rb', line 34

def execute(type, object)
  block_given? ? executor(type, object).execute(&Proc.new) : executor(type, object).execute
end