Class: Bade::Runtime::Block

Inherits:
Object show all
Defined in:
lib/bade/runtime/block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Block

Returns a new instance of Block.

Parameters:



18
19
20
21
# File 'lib/bade/runtime/block.rb', line 18

def initialize(name, &block)
  @name = name
  @block = lambda &block unless block.nil?
end

Instance Attribute Details

#blockProc (readonly)

Returns:

  • (Proc)


10
11
12
# File 'lib/bade/runtime/block.rb', line 10

def block
  @block
end

#nameString (readonly)

Returns:



14
15
16
# File 'lib/bade/runtime/block.rb', line 14

def name
  @name
end

Instance Method Details

#call(*args) ⇒ Object



23
24
25
# File 'lib/bade/runtime/block.rb', line 23

def call(*args)
  @block.call(*args) unless @block.nil?
end

#call!(*args) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/bade/runtime/block.rb', line 27

def call!(*args)
  if @block.nil?
    raise RuntimeError, "`#{@name}` must have block definition"
  else
    @block.call(*args)
  end
end