title: Capture helper without html buffer
body: <p>I have a view helper that wraps a block call in a <code>catch</code> statement to ensure some <code>throw</code> gets handeled properly:</p>
  
  <pre><code>def if_reachable(&amp;block)
    catch(:unreachable) do
      capture(&amp;block)
    end
  end
  </code></pre>
  
  <p>I can use the helper in my slim views like this</p>
  
  <pre><code>- if_reachable do
    | I won't be printed cause something is not reachable
    - throw(:unreachable)
  </code></pre>
  
  <p>The important part is that in my view I don't see the text <code>I won't be printed...</code>. That's the reason for the use of Rails' <code>capture</code> helper.</p>
  
  <p>The problem is, that I also want to use the same helper in inline ruby as well:</p>
  
  <pre><code>/ this is also inside a slim template
  - data = if_reachable { my_service.load_data }
  </code></pre>
  
  <p>and if no <code>:unreachable</code> is thrown I want to have the return value of <code>my_service.load_data</code>.</p>
  
  <blockquote>
    <p>The problem is: When no template is involved, the <code>capture</code> helper always returns <code>nil</code> and throws away the return value of <code>my_service.load_data</code></p>
  </blockquote>
  
  <p>Some ways I already considered would be</p>
  
  <p><strong>Writing a seperate helper function:</strong> That would be confusing to know which helper when to use.</p>
  
  <p><strong>Wrapping inline template ruby code into their own helper methods and use <code>return</code>:</strong> Would be confusing if a developer tries to use the helper and it can't be used without a seperate helper method</p>
  
  <pre><code>def my_helper
    if_reachable do
      return my_service.load_data
    end
  end
  </code></pre>
  
  <p>Any idea how to solve this? Is it possible to check if a block comes from a template or is pure ruby?</p>