diff --git a/guide/under-the-hood.md b/guide/under-the-hood.md index ba5744d..43b9830 100644 --- a/guide/under-the-hood.md +++ b/guide/under-the-hood.md @@ -339,3 +339,51 @@ end ``` This is a little mind-bending. We’re now always passing a block to `view_template`, that yields self to the block that was passed to `call` if a block was passed. + +The final `Component` class should look like this — just 33 lines of Ruby: + +```ruby +class Component + def call(buffer = []) + @buffer = buffer + view_template { yield(self) if block_given? } + @buffer.join + end + + def div(content = nil, **attributes) + @buffer << "