What I want to do is define a method that gets the result of every method in a block (or calls every method in a block) and returns the resultant string...
For example:
def a_method(&block)
## build a string by calling each of the blocks methods
end
def brackets(str)
'('+str+')'
end
a_method do
brackets "foo"
brackets "bar"
end
# desired output => (foo)(bar)
I tried putting yield in a_method, but as I expected that just returns the last evaluated expression from the block (in this case, (bar)).
I've looked around on how to build a string from calls inside a block, but can't find anything. I would have thought this would be quite a common technique.. could someone explain how?