Parameters
In this page:
Parameters
Method parameters are listed in the definition's parentheses and become local variables available inside the method body. Arguments are matched positionally by default, in the order they're passed at the call site. Ruby raises an ArgumentError if the number of arguments doesn't match what the method expects (unless defaults or splat parameters are used).
Note: Ruby raises ArgumentError immediately if you call a method with the wrong number of required arguments.
Example: Parameters
def greet(name, times)
times.times { puts "Hello, #{name}!" }
end
greet("Sam", 2)
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: