[Ruby] [Ruby]puts and return, difference between output and return value

less than 1 minute read

puts only outputs. On the other hand, return just returns the return value. puts cannot be used to pass values. return does not output.

puts.rb


def greet
    puts "Hello"
end
@example = greet
@example =>nil

return.rb


def greet2
    return "Hello"
end
@example2 = greet2
@example => "Hello"

Is it a mistake to use properly in terms of whether or not to pass values? I don’t have enough study on return values

Tags:

Updated: