can't override a cgi function, please help

C

Cere Davis

This is soooo driving me crazy!

I'm just trying to override the checkbox function on the CGI ruby
library and can not. Can someone tell me what I am doing wrong?

Simply:

require 'cgi'

class << CGI
def checkbox(name="",val=nil,checked=nil)
puts "asdf"
puts @params[name]
end
end

cgi=CGI.new('html3')
cgi.out() do
cgi.html() do
cgi.body() do
cgi.form("get") do
cgi.checkbox('box','true',"checd") +
cgi.br +
cgi.submit("Okey Dokey?")
end
end
end
end

then I run

!./mycgipro stuff=dddd


but it doesn't print out the "asdf" garbage that I overroad the function
with...

What's up? Does anyone know how to do this. I'm new to overriding in Ruby.

Related to this is the "input(attributes)" function but I can't seem to
trace what this is doing or where the input function even comes from.

Thanks,
Cere
 
G

Gavin Sinclair

This is soooo driving me crazy!
I'm just trying to override the checkbox function on the CGI ruby
library and can not. Can someone tell me what I am doing wrong?

require 'cgi'
class << CGI
def checkbox(name="",val=nil,checked=nil)
puts "asdf"
puts @params[name]
end
end
cgi=CGI.new('html3')
cgi.out() do
cgi.html() do
cgi.body() do
cgi.form("get") do
cgi.checkbox('box','true',"checd") +
cgi.br +
cgi.submit("Okey Dokey?")
end
end
end
end

You're creating/overriding a *class* method of CGI, not an *instance*
method. Try -- with the code above -- calling 'CGI.checkbox(...)' and
see what happens.

Do this:

class CGI
def checkbox(...)
...
end
end

Cheers,
Gavin
 
C

Cere Davis

That was actually the first thing I tried but I figured I would just
trial and error my way through soem Ruby syntax and class << CGI was my
next guess. Thanks for clarifying the difference. As it happens
though, this makes no difference. Again, I think this may have
something to do with the input(attributes) function at the bottom of the
original cgi class. Something about these variables get precidence
over any overriding variables???

Me no understand...
 
C

Cere Davis

Oops. I spoke a little too soon. I do get something:

An undefined method error on checkbox.

So I need to define this method as public or something?

How would I overrride a checkbox instance without calling having to call
a new CGI class? Ideally, I would just like it to be overriden in the
main CGI class and inherited in when I make a CGI.new.

Thanks,
cere
 
G

gabriele renzi

Oops. I spoke a little too soon. I do get something:

An undefined method error on checkbox.

So I need to define this method as public or something?

How would I overrride a checkbox instance without calling having to call
a new CGI class? Ideally, I would just like it to be overriden in the
main CGI class and inherited in when I make a CGI.new.

I think oyu messed up something. Anyway you don't jave to use 'puts'
you just should return a string from the method
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top