From: Dmitry Borodaenko Date: 2003-08-08T21:08:50+09:00 Subject: Can't inherit CGI from cgi.rb I thought it would be trivial to derive a class from CGI and add some instance variables to it, however: require 'cgi' class SamizdatCGI < CGI def initialize super @session = Session.new(self) end attr_reader :session end cgi = SamizdatCGI.new As soon as I pass some parameters into such script, I get the following error: /usr/lib/ruby/1.6/cgi.rb:1595:in `class_eval': (eval):1:in `remove_const': constant SamizdatCGI::CGI_PARAMS not defined (NameError) from /usr/lib/ruby/1.6/cgi.rb:1595:in `class_eval' from /usr/lib/ruby/1.6/cgi.rb:1595:in `initialize' from /usr/lib/ruby/1.6/cgi.rb:1593 Offending code in cgi.rb is (it is the same in cgi.rb from Ruby 1.8): initialize_query() # set @params, @cookies eval "CGI_PARAMS = @params.nil? ? nil : @params.dup" eval "CGI_COOKIES = @cookies.nil? ? nil : @cookies.dup" if defined?(MOD_RUBY) and (RUBY_VERSION < "1.4.3") raise "Please, use ruby1.4.3 or later." else at_exit() do if defined?(CGI_PARAMS) self.class.class_eval("remove_const(:CGI_PARAMS)") ^ self.class.class_eval("remove_const(:CGI_COOKIES)") end end end Is it a bug in cgi.rb, or in Ruby? If it's intended to not to allow to inherit from CGI, is there some other elegant way to generate custom instance variables from CGI.new ? -- Dmitry Borodaenko