Return value problem

Hi
What is happen for return value in these 2 codes ?
(Please analysis for me result of these 2 codes)


def test1(name)
puts “Hello”+name
end

def test2(name)
puts “Hello”+name
1+1
end

return_value1 = test1(“amir”)
puts return_value1

return_value2 = test2(“amir”)
puts return_value2


If you don’t explicitly return anything, ruby returns the value of the
last expression.

On Wed, Aug 4, 2010 at 3:52 PM, Alex S. [email protected] wrote:

On Wed, Aug 4, 2010 at 5:40 PM, Amir E. [email protected]
wrote:

What is happen for return value in these 2 codes ?
(Please analysis for me result of these 2 codes)

$ cat i.rb
def test1(name)
puts “Hello”+name
end

def test2(name)
puts “Hello”+name
1+1
end

return_value1 = test1(“amir”)
p return_value1

return_value2 = test2(“amir”)
p return_value2

$ ruby i.rb
Helloamir
nil
Helloamir
2

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs