8. how i dealt with def greeter


#1

def greeter(name)
    puts "Hello, #{name}"
end

greeter("Sam")

The instructions insist on using return to display the greeting, but I could not get that to work. Instead, I used puts and it works just fine. This is technically not correct, so how could I get the code to work using return?


#2

been a while since i done ruby, but in general if something is returned, you can either store it in a variable, or print it directly when you call the function:

puts greeter("Sam")

use return in the function. You do understand how return works?


#3

now that you mention it im not too certain on how return works


#4

return does what is says, it returns something. You can see this if you store the result of the function call in a variable:

def greeter(name)
    return "Hello, #{name}"
end

result = greeter("Sam")
puts result

the returned result is stored in the variable