Rendering block content from erb
If you want to create any methods which returns block content and you calling this methods in erb (slim, haml, etc) — you can have a big problems. For example — you can see repetition of content in your browser or even worse.
Let our methods are as follows:
@head_html ||= 
@head_html << block if block_given?
return unless @head_html
But what if you can not use these methods, or they have too much overhead for a current task?
Such a case arose in my pull request in sidekiq, where I wrote a simple variant of the capture for erb files:
I hope it will be useful. Happy hacking!