John John - 5 months ago 8
Ruby Question

method is not returning anything

I'm a newbie in Ruby, and could anybody please answer why the following code is not producing any output?:

def method(name)
return "Hello + #{name}"
end

method("Amy")


It's not giving me any result

Answer

Which output? It only returns string. You need to print it or something. Replace last method call with:

puts method("Amy")

Then you'll notice you probably don't need that + because you are already adding name as part of string