From: Alex Young Date: 2006-07-24T21:44:52+09:00 Subject: Re: Autoloading objects — Ruby equivalent for PHP5 "__autoload Marcin Mielżyński wrote: > Naum T. wrote: > >> Does there exist a Ruby equivalent to PHP5 "magic" __autoload method >> that spares the developer from detailing a list of "require" statements? >> http://us2.php.net/autoload >> >> Or is this something that a homebrewed solution is necessary? Like >> catching the exception and testing for file existence, etc.… or is >> there a gem/extension featuring this functionality? >> > > Sure there is ;D > > Kernel#autoload: > http://ruby-doc.org/core/classes/Kernel.html#M002963 > > and: > > Module#autoload: > http://ruby-doc.org/core/classes/Module.html#M001061 That's not quite it. You need to call Module.autoload yourself. PHP's autoload is called by the interpreter to perform the inclusion. You could use const_missing to get a similar functionality, though... def Object.const_missing(name) load name.to_lower + ".rb" end That's got a few rough edges, though, to put it mildly... -- Alex