Professional Web Applications Themes

Can't inherit CGI from cgi.rb - Ruby

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 ...

  1. #1

    Default 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

    Dmitry Borodaenko Guest

  2. #2

    Default Re: Can't inherit CGI from cgi.rb

    On Fri, Aug 08, 2003 at 09:08:50PM +0900, Dmitry Borodaenko wrote:
    > 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
    Yeah, it's a bit wierd and inconvenient, and an unnecessary use of constants
    IMO. It could certainly be made more flexible.

    You can work around it; download ruby-fcgi-0.8.3 from RAA to see how it's
    done.

    Regards,

    Brian.

    Brian Candler Guest

Similar Threads

  1. How to inherit a web user control
    By chyong in forum ASP.NET Building Controls
    Replies: 1
    Last Post: July 24th, 10:23 PM
  2. Inherit from a Web User Control
    By Magnus Strandberg in forum ASP.NET Building Controls
    Replies: 3
    Last Post: February 23rd, 10:59 AM
  3. Inherit Datagrid
    By Martin Kulov in forum ASP.NET Building Controls
    Replies: 2
    Last Post: August 12th, 03:19 PM
  4. Using bookmarks with Inherit zoom??!!
    By James_L_Shaffer@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 1
    Last Post: April 27th, 05:50 AM
  5. inherit DataColumnCollection
    By Frank in forum ASP.NET General
    Replies: 0
    Last Post: July 8th, 09:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139