Difference between parameters and arguments

The words “parameters” and “arguments” are often used interchangeably, but there is a technical difference between the two terms. The word “parameters” is for when methods are being defined and “arguments” is for when messages are passed to objects. For example, in the following method definition, the x and y parameters are used:

class Example
  def multiply(x, y)
    x * y
  end
end

When an instance of the Example class is created and the multiply message is sent to the receiver, the numbers that are sent are referred to as arguments. In the following code snippet, 3 and 4 are arguments.

ex = Example.new
ex.send(:multiply, 3, 4)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s