From: Mat Schaffer Date: 2006-07-25T22:00:13+09:00 Subject: Re: Autoloading objects — Ruby equivalent for PHP5 "__autoload On Jul 25, 2006, at 7:22 AM, Gonzalo Garramuno wrote: > Naum T. escribi�: >> 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? >> > > def Object.const_missing elem > require elem.to_s > end > > a = A.new > > PS. I would advise *NOT* doing this kind of thing, thou. It can make > your code much harder to debug for other developers. you need > def Object.const_missing elem > require elem.to_s const_get(elem) > end To make this work, otherwise the 'A' in A.new becomes the return value of 'require elem.to_s' -Mat