ruby website code ignores function

E

Edward

When I run the following script as a web page, it ignores the output of
my function and doesn't print the "test2" as if there is a problem with
the function. How can I fix this? I pasted the code below.

View Example: http://www.tanguay.info/learnruby/nofunction.rb

Thanks,

Edward Tanguay
All my projects: http://www.tanguay.info

=====================================

#!/usr/bin/ruby
print "Content-type: text/plain\n\n"

3.times { print "Hello World\n" }
print "test1"
print sayHello("Jim")
print "test2"

def sayHello(name)
result = "Hello" + name
return result
end
 
A

ara.t.howard

When I run the following script as a web page, it ignores the output of
my function and doesn't print the "test2" as if there is a problem with
the function. How can I fix this? I pasted the code below.

View Example: http://www.tanguay.info/learnruby/nofunction.rb

Thanks,

Edward Tanguay
All my projects: http://www.tanguay.info

=====================================

#!/usr/bin/ruby
print "Content-type: text/plain\n\n"

3.times { print "Hello World\n" }
print "test1"
print sayHello("Jim")
print "test2"

def sayHello(name)
result = "Hello" + name
return result
end

as with cgis in any language, always, always, always make sure they can run
from the command line, preferably as the webuser. doing so in this can shows:

harp:~ > cat a.rb
#!/usr/bin/ruby
print "Content-type: text/plain\n\n"

3.times { print "Hello World\n" }
print "test1"
print sayHello("Jim")
print "test2"

def sayHello(name)
result = "Hello" + name
return result
end



harp:~ > ruby a.rb </dev/null
Content-type: text/plain

Hello World
Hello World
Hello World
a.rb:6: undefined method `sayHello' for main:Object (NoMethodError)


in ruby, functions must be defined before they are used.

kind regards.

-a
 

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

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top