From: Joel VanderWerf Date: 2007-07-28T02:10:09+09:00 Subject: Re: eval versus load and plugins Rover Rhubarb wrote: > 2. Is there some nicer, cleaner way of doing what I'm doing without > having the plugin file define a global method? You can module_eval the file in the context of a new (anonymous, if you like) module. Here's one way to do that: [~/tmp] cat main.rb require 'script' # http://redshift.sourceforge.net/script/ plugin_module = Script.load("plugin.rb") # either: plugin_class = plugin_module::PluginClass p plugin_class.new.foo # or: plugin_class = plugin_module.get_the_plugin_class p plugin_class.new.foo [~/tmp] cat plugin.rb class PluginClass def foo "FOO" end end def get_the_plugin_class # NOT really global -- in module scope PluginClass end [~/tmp] ruby main.rb "FOO" "FOO" -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407