Class: Hollaback::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/hollaback/callback.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, execute = nil, &block) ⇒ Callback

Returns a new instance of Callback.



5
6
7
8
# File 'lib/hollaback/callback.rb', line 5

def initialize(type, execute = nil, &block)
  @type       = type
  @executable = (execute ? execute : block)
end

Instance Attribute Details

#executableObject (readonly)

Returns the value of attribute executable.



3
4
5
# File 'lib/hollaback/callback.rb', line 3

def executable
  @executable
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/hollaback/callback.rb', line 3

def type
  @type
end

Instance Method Details

#buildObject



10
11
12
13
14
15
16
17
# File 'lib/hollaback/callback.rb', line 10

def build
  case executable
  when Symbol
    -> (target, &block) { target.send(executable, &block) }
  when Proc
    -> (target) { target.instance_eval(&executable) }
  end
end