Forum: Ruby newbie: functions don't work in script

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Christoph K. (Guest)
on 2006-01-12 15:42
sorry for this newbie question, just started ruby programming today,

Try to work me through the book Programming Ruby

the script:

#!/usr/local/bin/ruby
a = [ "a", "b", "c" ]
a.include?("b")

returns me nothing,
if I do the same in "irb"
it returns "true"

why does it not work in the shell script??
Hannes W. (Guest)
on 2006-01-12 16:04
(Received via mailing list)
Christoph,

your script doesn't do anything with the return-value of 'include?'

try this:

#!/usr/local/bin/ruby
a = [ "a", "b", "c" ]
p a.include?("b")
PWR (Guest)
on 2006-01-12 16:04
(Received via mailing list)
Try changing the last line of your script to,
puts a.include?("b")
irb automatically prints out the evaluation of an expression.

Peter.
Christoph K. (Guest)
on 2006-01-12 16:13
PWR wrote:
> Try changing the last line of your script to,
> puts a.include?("b")
> irb automatically prints out the evaluation of an expression.
>
> Peter.

thx a lot, now I got it!
This topic is locked and can not be replied to.