# Ruby website code ignores function

**URL:** <https://www.ruby-forum.com/t/ruby-website-code-ignores-function/67956>\
**Category:** Ruby\
**Created:** [September 8, 2006, 4:20am UTC](https://www.ruby-forum.com/t/ruby-website-code-ignores-function/67956 "2006-09-08T04:20:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![edward](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/90db22/32.png) [@edward](https://www.ruby-forum.com/u/edward)\
**Post date:** [September 8, 2006, 4:20am UTC](https://www.ruby-forum.com/t/ruby-website-code-ignores-function/67956/1 "2006-09-08T04:20:41Z")

</div>

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](http://www.tanguay.info/learnruby/nofunction.rb)

Thanks,

Edward Tanguay  
All my projects: [http://www.tanguay.info](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

---

<div class="post-metadata">

**Author:** ![edward](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/90db22/32.png) [@edward](https://www.ruby-forum.com/u/edward)\
**Post date:** [September 8, 2006, 4:38am UTC](https://www.ruby-forum.com/t/ruby-website-code-ignores-function/67956/2 "2006-09-08T04:38:45Z")

</div>

On Fri, 8 Sep 2006, Edward wrote:

> 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

---

<div class="post-metadata">

**Author:** ![edward](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/90db22/32.png) [@edward](https://www.ruby-forum.com/u/edward)\
**Post date:** [September 8, 2006, 5:24am UTC](https://www.ruby-forum.com/t/ruby-website-code-ignores-function/67956/3 "2006-09-08T05:24:48Z")

</div>

right, I didn’t have ruby installed locally (windows) but I can ssh  
onto the site and test it there, THANKS for the tip!

Edward Tanguay  
All my projects: [http://www.tanguay.info](http://www.tanguay.info)
