# Re: The Ruby/ERB way to do this?

**URL:** <https://www.ruby-forum.com/t/re-the-ruby-erb-way-to-do-this/100202>\
**Category:** Ruby\
**Created:** [July 27, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/re-the-ruby-erb-way-to-do-this/100202 "2006-07-27T18:41:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [July 27, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/re-the-ruby-erb-way-to-do-this/100202/1 "2006-07-27T18:41:59Z")

</div>

Thanks for taking the time to reply. Using a variable of require is a  
good  
idea.

Referencing variables as X::Size seems verbose. Is there any way for  
require  
to define a set of local scoped variables so the ERB template could drop  
the  
X:: prefix?

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [July 27, 2006, 7:59pm UTC](https://www.ruby-forum.com/t/re-the-ruby-erb-way-to-do-this/100202/2 "2006-07-27T19:59:45Z")

</div>

Well a couple of ideas there.

If you include the Module (X) then you don’t have to use the X:: prefix  
when  
referencing the constants they become part of the local namespace and  
this  
is true in the erb template which is executing using the binding.

So if you have a file myconstants.rb  
module MyConstants  
Foo = ‘bar’  
end

And your program does this

require ‘erb’  
require ‘myconstants’  
include MyConstants

erb = ERB.new ‘my template here \<%= Foo %\>’

b = binding

puts erb.result(b) # gives you 'my template here bar

Jeff
