results are different by running script via irb and ruby

J

John Wu

Hey,

I am new to ruby. I have the following simple ruby script
def make_show_name(show)
return Proc.new {|host| show + " with " + host}
end
show = make_show_name("Practical Cannibalism")
show.call("H. Annabellector")

when run this using irb, it prints out: Practical Cannibalism with H.
Annabellector
but when I saved this as test.rb and type ruby test.rb, it prints out
nothing.

What is the problem here?

Thanks!
 
J

Jean-Julien Fleck

Hello,

I am new to ruby. I have the following simple ruby script
def make_show_name(show)
=A0return Proc.new {|host| show + " with " + host}
end
show =3D make_show_name("Practical Cannibalism")
show.call("H. Annabellector")

when run this using irb, it prints out: Practical Cannibalism with H.
Annabellector
but when I saved this as test.rb and type ruby test.rb, it prints out
nothing.

What is the problem here?

irb automaticaly prints out the value of the last expression, but your
script does not.

Try

puts show.call("H. Annabellector")

and it should be fine.

Cheers,


--=20
JJ Fleck
PCSI1 Lyc=E9e Kl=E9ber
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top