Ruby 3 · Basics

Define a method with keyword arguments

Keyword arguments make calls self-documenting. The last expression is returned.

def greet(name:, greeting: "Hello")
  "#{greeting}, #{name}!"
end

puts greet(name: "Ada")

Official Ruby 3 documentation

More basics commands

All basics commands · Ruby 3 cheatsheet

Was this page helpful?