I have two ways I might need to call some code using a block.
Option 1:
foo()
Option 2:
block_function do
foo()
end
How do I switch between the two of these at runtime? I really don’t want to do the following, because foo() is actually a whole lot of code:
if condition then
foo()
else
block_function do
foo()
end
end
Or as others suggested, make the
foo()bunch of code an actual method and write what you wrote in the OP.More generic version as @tadman suggests:
@Christian Oudard added a comment specifying the specific problem, optionally decorating a code block with div do…end with Erector. This suggests another approach: