DEV Community

Dedé Menezes
Dedé Menezes

Posted on

Parameters VS Arguments with Ruby

In programming, the terms parameter and argument are often used interchangeably, but they have distinct meanings. Understanding the difference is crucial for a developer. Let’s break it down.

Parameters

Parameters are the variables that are listed in the method definition. They act as placeholders for the values that will be passed to the method when it is called.

Example:

def greet(name)
  puts "Hello, #{name}!"
end
Enter fullscreen mode Exit fullscreen mode

In this example, name is a parameter of the greet method. It specifies that the method expects a value to be provided when it is called.

Arguments

Arguments are the actual values that you pass to a method when you call it. These are the concrete instances that replace the parameters defined in the method.

Example:

greet("Alice")
Enter fullscreen mode Exit fullscreen mode

In this line, "Alice" is the argument. When you call greet("Alice"), the argument "Alice" replaces the parameter name in the method definition, allowing the method to execute with that specific value.

Top comments (0)