# Re: Loading, CGI and some aother questions

**URL:** <https://www.ruby-forum.com/t/re-loading-cgi-and-some-aother-questions/75642>\
**Category:** Ruby\
**Created:** [November 11, 2006, 9:12pm UTC](https://www.ruby-forum.com/t/re-loading-cgi-and-some-aother-questions/75642 "2006-11-11T21:12:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gambler\_Gluck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@Gambler\_Gluck](https://www.ruby-forum.com/u/Gambler_Gluck)\
**Post date:** [November 11, 2006, 9:12pm UTC](https://www.ruby-forum.com/t/re-loading-cgi-and-some-aother-questions/75642/1 "2006-11-11T21:12:31Z")

</div>

Well, configs are mine anyway, so I’m not afraid of injection from those  
files. But how do I “source” a file? Kernel#load and Kernel#require  
return boolean and do not seem to affect local scope. Could you please  
provide a code example?

----- Original Message ----

The sourcing a .rb file is more flexible, however you risk code  
injection that way. Usual considerations apply.

David V.

---

<div class="post-metadata">

**Author:** ![Gambler\_Gluck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@Gambler\_Gluck](https://www.ruby-forum.com/u/Gambler_Gluck)\
**Post date:** [November 11, 2006, 9:22pm UTC](https://www.ruby-forum.com/t/re-loading-cgi-and-some-aother-questions/75642/2 "2006-11-11T21:22:32Z")

</div>

On Sun, 12 Nov 2006, Gambler Gluck wrote:

> Well, configs are mine anyway, so I’m not afraid of injection from those  
> files. But how do I “source” a file? Kernel#load and Kernel#require return  
> boolean and do not seem to affect local scope. Could you please provide a  
> code example?

eval IO.read(config)

it’s evil - pure evil. i’d use yaml if possible.

-a

---

<div class="post-metadata">

**Author:** ![Gambler\_Gluck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@Gambler\_Gluck](https://www.ruby-forum.com/u/Gambler_Gluck)\
**Post date:** [November 11, 2006, 9:26pm UTC](https://www.ruby-forum.com/t/re-loading-cgi-and-some-aother-questions/75642/3 "2006-11-11T21:26:33Z")

</div>

Gambler Gluck wrote:

> Well, configs are mine anyway, so I’m not afraid of injection from those files. But how do I “source” a file? Kernel#load and Kernel#require return boolean and do not seem to affect local scope. Could you please provide a code example?

eval / instance\_eval / class\_eval the contents of the file instead. You  
could also do as Rails does in for example config/routes.rb and provide  
an API to configure your app in a singleton. (Even is singletons are  
slightly evil with respects to unit testing, configuration isn’t a  
component whose state changes at runtime as part of regular operation -  
i.e. only explicitly, not as a business logic side effect, so you can  
probably get away with that approach.)

David V.
