From: Piotr Biedruna
Date: 2007-03-21T01:19:56+09:00
Subject: Re: Autoloading objects �? Ruby equivalent for?
Mat Schaffer wrote:
> const_missing is a little more like PHP's __autoload function.
>
> The following, for example will attempt to just do: require name> in the event it can't find the class.
>
> def Object.const_missing name
> require name.to_s.downcase
> const_get(name)
> end
Well, th const_missing sollution does work, but only in scripts called
directly in shell by 'ruby' executable. When using it in script called
in browser i get:
[Tue Mar 20 16:56:49 2007] [error] mod_ruby: error in ruby
[Tue Mar 20 16:56:49 2007] [error] mod_ruby:
/home/services/httpd/html/TRON/ruby/index.rb:11: uninitialized constant
#::Test (NameError)
[Tue Mar 20 16:56:49 2007] [error] mod_ruby: from
/usr/lib/ruby/1.8/apache/ruby-run.rb:38:in `load'
[Tue Mar 20 16:56:49 2007] [error] mod_ruby: from
/usr/lib/ruby/1.8/apache/ruby-run.rb:38:in `handler'
Got apache 2.2 with mod_ruby configured as follows:
LoadModule ruby_module modules/mod_ruby.so
AddType text/html .rb
RubyRequire apache/ruby-run
Options +ExecCGI
SetHandler ruby-object
RubyHandler Apache::RubyRun.instance
What i`ve been trying to get is an equivalent of PHP __autoload()
routine working under both shell execution and apache handler. Know any?
--
Posted via http://www.ruby-forum.com/.