Say I have function with_foo that takes a block, and wrap it around a piece of code, like
with_foo do
puts "hello!"
end
Now I would like to make the wrapping conditional, like
if do_with_foo?
with_foo do
puts "hello!"
end
else
puts "hello!" # without foo
end
Is there any way to write this shorter/more elegantly, meaning without having to repeat the code puts "hello!"?
if you are willing to specify argument with a block, it is possible.
given
with fooabove, you can write such snippet: