Problem with return value

  • Thread starter Amir Ebrahimifard
  • Start date
A

Amir Ebrahimifard

Hi
In this code :
-------------------------------

def test_method(name)
puts name
3+5
end


return_value = test_method("James")
puts return_value
 
M

Matthew Bloch

Hi
In this code :
-------------------------------

def test_method(name)
puts name
3+5
end


return_value = test_method("James")
puts return_value

Because in Ruby, the last statement executed in a block is the block's
value. That goes for your test_method's return value, and any other
type of block you use.
 
B

brabuhr

def test_method(name)
=A0puts name
=A03+5
end


return_value =3D test_method("James")
puts return_value

irb(main):001:0> def test_method(name)
irb(main):002:1> rv =3D puts(name)
irb(main):003:1> 3+5
irb(main):004:1> rv
irb(main):005:1> end
=3D> nil
irb(main):006:0> return_value =3D test_method("James")
James
=3D> nil
irb(main):007:0> puts return_value
nil
=3D> nil
 

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,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top