MΓ³dulo 01 Β· Ruby Basics β LecciΓ³n 5 de 6 Β· ~9 min
Methods
def / end, and the implicit return
Swift declares a function with func. Ruby uses def, closed with end β same as every other Ruby block:
def greet(name)
"Hello, #{name}!"
endLook closely: there's no return keyword in that method, yet it hands back the greeting. This is the single biggest habit to build: a Ruby method automatically returns the value of the LAST expression it evaluates. You can write return explicitly, and you will for early exits β but for the normal "compute a value and hand it back" case, idiomatic Ruby leaves return off entirely.