Class: Hollaback::Callback
- Inherits:
-
Object
- Object
- Hollaback::Callback
- Defined in:
- lib/hollaback/callback.rb
Overview
A callback that can be executed later
Instance Attribute Summary collapse
-
#executable ⇒ Object
readonly
Returns the value of attribute executable.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(type, execute = nil, &block) ⇒ Callback
constructor
A new instance of Callback.
Constructor Details
#initialize(type, execute = nil, &block) ⇒ Callback
Returns a new instance of Callback.
8 9 10 11 |
# File 'lib/hollaback/callback.rb', line 8 def initialize(type, execute = nil, &block) @type = type @executable = (execute || block) end |
Instance Attribute Details
#executable ⇒ Object (readonly)
Returns the value of attribute executable.
6 7 8 |
# File 'lib/hollaback/callback.rb', line 6 def executable @executable end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/hollaback/callback.rb', line 6 def type @type end |
Instance Method Details
#build ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hollaback/callback.rb', line 13 def build case executable when Symbol ->(target, &block) { target.send(executable, &block) } when Proc ->(target) { target.instance_eval(&executable) } else raise ArgumentError, "Invalid callback argument: #{executable.inspect}" end end |