From: Joel VanderWerf Date: 2005-06-11T06:15:57+09:00 Subject: Re: Is there a Ruby equivilant to Python's exec_file? Ara.T.Howard wrote: > On Sat, 11 Jun 2005, Joel VanderWerf wrote: > >> Wayne Pierce wrote: >> >>> I'm working on a white-box security auditing framework, which is >>> currently written in Python and makes use of exec_file to load some >>> security scans at startup. Is there a way to do the same thing in >>> Ruby? >>> >>> For those not familiar with Python, exec_file allows me to read an >>> external file and save the resulting objects to a hash/dictionary of >>> my choosing. I can then check the values or execute functions that >>> have been saved in my hash. >> >> >> Check out "script" on RAA: http://raa.ruby-lang.org/project/script. > > > that's very cool joel! i did something with a similar intent, but slight > different impl, at > > http://raa.ruby-lang.org/project/dynaload/ One difference: using script.rb, the loaded file doesn't have to know that it is being used in that way. The entire file (and its local dependencies) are encapsulated, rather than only the selected modules that you pass to Dynaload::export. I like the #modules and #classes methods of Dynaload. Maybe I will borrow that for Script instances. Maybe they should even be instance methods of Module. It might make sense to propose something like these two libraries as RCRs, since so many people either ask for it or reinvent it, but the implementation is so easy that it's probably not worth it...