From: Rob Biedenharn Date: 2010-08-07T03:17:22+09:00 Subject: Re: Problem with return value On Aug 6, 2010, at 12:27 PM, Matthew Bloch wrote: > On 06/08/2010 17:23, Amir Ebrahimifard wrote: >> Hi >> In this code : >> ------------------------------- >> >> def test_method(name) >> puts name >> 3+5 >> end >> >> >> return_value = test_method("James") >> puts return_value >> ------------------------------- >> >> why when the last statement executed , "puts" does not return "nil" >> and >> return 8? > > 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. > > -- > Matthew Bloch > Actually, 3+5 is the last statement in your test_method. Are you surprised that the value is 8? -Rob Rob Biedenharn Rob@AgileConsultingLLC.com http://AgileConsultingLLC.com/ rab@GaslightSoftware.com http://GaslightSoftware.com/