# ERB question, not seeing variables

**URL:** <https://www.ruby-forum.com/t/erb-question-not-seeing-variables/110005>\
**Category:** Ruby\
**Created:** [July 21, 2007, 2:48am UTC](https://www.ruby-forum.com/t/erb-question-not-seeing-variables/110005 "2007-07-21T02:48:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [July 21, 2007, 2:48am UTC](https://www.ruby-forum.com/t/erb-question-not-seeing-variables/110005/1 "2007-07-21T02:48:46Z")

</div>

I’m trying to do some template parsing in a class… here is my class:

require ‘erb’  
class TemplateParser  
def TemplateParser.parse(template, params)  
params.each do |k,v|  
self.instance\_variable\_set(:"@#{k}",v)  
end  
template\_content = ‘’  
File.open(template, “r”) do |f|  
while line = f.gets  
template\_content \<\< line  
end  
end  
e = ERB.new(template\_content, 0, “%\<\>”)  
e.result  
end  
end

so in my template… if I have a variable called “revisions”. and it is  
set in the params[:revisions] hash. It defines an instance on the class  
called revisions, but ERB is not seeing that… What can I do get around  
this?

Thanks

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [July 21, 2007, 3:33am UTC](https://www.ruby-forum.com/t/erb-question-not-seeing-variables/110005/2 "2007-07-21T03:33:35Z")

</div>

> ```
> e = ERB.new(template_content, 0, "%<>")
> e.result
> 
> ```

I’m not sure if it will be helpful in your situation, but e.result  
will accept a binding parameter. That binding is used to resolve local  
variables in the template.

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [July 21, 2007, 3:52am UTC](https://www.ruby-forum.com/t/erb-question-not-seeing-variables/110005/3 "2007-07-21T03:52:33Z")

</div>

Jesse Brown wrote:

> > ```
> > e = ERB.new(template_content, 0, "%<>")
> > e.result
> > 
> > ```
> 
> I’m not sure if it will be helpful in your situation, but e.result  
> will accept a binding parameter. That binding is used to resolve local  
> variables in the template.

yeah I got if figured out… thanks…

require ‘erb’  
class TemplateParser  
def TemplateParser.parse(template, params)  
params.each do |k,v|  
self.instance\_variable\_set(:"@#{k}",v)  
end  
template\_content = ‘’  
File.open(template, “r”) do |f|  
while line = f.gets  
template\_content \<\< line  
end  
end  
e = ERB.new(template\_content, 0, “%\<\>”)  
e.result(self.send(“binding”))  
end  
end
