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.
8a2f9d650da40a181074c8582271038f?d=identicon&s=25 Christoph Klocker (corck)
on 2006-01-12 14: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??
9d0207c91dd4cbc7e7b5f5be98c85e2b?d=identicon&s=25 Hannes Wyss (Guest)
on 2006-01-12 15: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")
03a22000d0808f1e35e76aab1a16469d?d=identicon&s=25 PWR (Guest)
on 2006-01-12 15: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.
8a2f9d650da40a181074c8582271038f?d=identicon&s=25 Christoph Klocker (corck)
on 2006-01-12 15: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.