Class: Bade::Runtime::Block
- Inherits:
-
Object
- Object
- Bade::Runtime::Block
- Defined in:
- lib/bade/runtime/block.rb
Direct Known Subclasses
Defined Under Namespace
Classes: MissingBlockDefinitionError
Instance Attribute Summary collapse
- #block ⇒ Proc readonly
- #name ⇒ String readonly
- #render_binding ⇒ RenderBinding readonly
Instance Method Summary collapse
-
#call(*args) ⇒ Object
— Calling methods.
- #call!(*args) ⇒ Object
-
#initialize(name, render_binding, &block) ⇒ Block
constructor
A new instance of Block.
-
#render(*args) ⇒ Object
— Rendering methods.
- #render!(*args) ⇒ Object
Constructor Details
#initialize(name, render_binding, &block) ⇒ Block
Returns a new instance of Block.
47 48 49 50 51 |
# File 'lib/bade/runtime/block.rb', line 47 def initialize(name, render_binding, &block) @name = name @render_binding = render_binding @block = block end |
Instance Attribute Details
#block ⇒ Proc (readonly)
33 34 35 |
# File 'lib/bade/runtime/block.rb', line 33 def block @block end |
#render_binding ⇒ RenderBinding (readonly)
41 42 43 |
# File 'lib/bade/runtime/block.rb', line 41 def render_binding @render_binding end |
Instance Method Details
#call(*args) ⇒ Object
— Calling methods
55 56 57 |
# File 'lib/bade/runtime/block.rb', line 55 def call(*args) call!(*args) unless @block.nil? end |
#call!(*args) ⇒ Object
59 60 61 62 63 |
# File 'lib/bade/runtime/block.rb', line 59 def call!(*args) raise MissingBlockDefinitionError.new(name, :call) if @block.nil? render_binding.__buff.concat(@block.call(*args)) end |
#render(*args) ⇒ Object
— Rendering methods
67 68 69 70 71 72 73 |
# File 'lib/bade/runtime/block.rb', line 67 def render(*args) if @block.nil? '' else render!(*args) end end |
#render!(*args) ⇒ Object
75 76 77 78 79 |
# File 'lib/bade/runtime/block.rb', line 75 def render!(*args) raise MissingBlockDefinitionError.new(name, :render) if @block.nil? @block.call(*args).join end |