# Modifying bindings

**URL:** <https://www.ruby-forum.com/t/modifying-bindings/155512>\
**Category:** Rails\
**Created:** [December 12, 2008, 7:25pm UTC](https://www.ruby-forum.com/t/modifying-bindings/155512 "2008-12-12T19:25:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![avramd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aca169/32.png) [@avramd](https://www.ruby-forum.com/u/avramd)\
**Post date:** [December 12, 2008, 7:25pm UTC](https://www.ruby-forum.com/t/modifying-bindings/155512/1 "2008-12-12T19:25:33Z")

</div>

Hello,

I have a little challenge that is frustrating me. I am trying to write  
a wrapper around cache() so that my fragments get cached with comments  
injected at the front and back. Unfortunately it is not as simple as  
using “concat(text,block.bindings)” before and after the call to  
cache() because then the comments themselves don’t get cached.

Here is what I have right now:

def wrap\_cache(path,&block)  
concat("", block.binding)  
cache(path,&block)  
concat("", block.binding)  
end

It produces the correct visual output, but the concat results aren’t  
part of the cached fragment, they are getting regenerated every time.  
What I need to do is something like this:

def wrap\_cache2(path,&block)  
cache(path) do  
concat(label\_frag(‘vvvvvvvvv’,path),block.binding)  
yield  
concat(label\_frag(’^^^^^^^^^’,path),block.binding)  
end  
end

But I need to give this new block the bindings of the original block,  
rather than have it grab a new set of bindings. With the above,  
cache() crashes b/c the inner block isn’t in the context of an erb  
template, so it’s missing key stuff (specifically \_erbout).

-Avram

“I realised something was wrong when I looked over and saw the mast in  
the water.” - Dean Barker, Team New Zealand skipper
