Created
April 26, 2020 17:32
-
-
Save paulcsmith/c0e2d0fc6b5bc95dd39b372ae5d41152 to your computer and use it in GitHub Desktop.
Mount with block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mount(component, *args, **named) | |
component.new(*args, **named).render do |*yield_args| | |
yield *yield_args | |
end | |
end | |
class Component | |
def initialize(@name : String) | |
end | |
def render | |
yield @name | |
end | |
end | |
mount Component, name: "paul" do |name| | |
puts name | |
end | |
mount(Component, name: "paul", &.upcase) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment