In Ruby, methods are blocks of reusable code. You define a method using the def
keyword followed by its name and any optional parameters.
Methods can return values using the return
keyword, or Ruby will return the last evaluated expression by default.
return
unless you need to exit early or be explicit.def
starts a method definitionend
closes itreturn
if needed