From: Brian Candler Date: 2010-03-12T18:07:04+09:00 Subject: Re: Dynamically require and include code in application R. Kumar wrote: > Just what i wanted, Brian. Now its just an instance method: > > def load_module requirename, includename > require "mylib/#{requirename}" > > extend Object.const_get("#{includename}") > send("#{requirename}_init") > end Slight simplification: extend Object.const_get(includename) (There's no need for string interpolation on that line; const_get will take either a symbol or a string) > I guess i could just lowercase the includename and have param. That's how Rails handles it: use conventions to convert filenames to module/class names and vice versa. >> require 'rubygems' => true >> require 'activesupport' => true >> "FooBar".underscore => "foo_bar" >> "foo_bar".camelize => "FooBar" >> "Foo::Bar".underscore => "foo/bar" >> "foo/bar".camelize => "Foo::Bar" -- Posted via http://www.ruby-forum.com/.