A method is a named, reusable chunk of code logic. In Ruby, you start a method with def and close it with end. Since a method automatically returns its last expression, you rarely need the return keyword.
ruby
def greet(name)
"Hello, #{name}!"
end
def add(a, b)
a + b
end
puts greet("Aung")
puts add(5, 7)greet takes a name and returns a greeting text. add adds two numbers together and returns the result.
You should see
Hello, Aung! 12Info
In Ruby methods, if the last line is a value, it's automatically returned.