Wednesday, June 8, 2011

Difference between Argument and Parameter in ruby on rails

A parameter represents a value that the method expects you to pass when you call it.
An argument represents the value you pass to a method parameter when you call the method. The calling code supplies the arguments when it calls the method.

In simple words, parameters appear in method definitions; arguments appear in method calls.

For example, in below method, variables param1 and param2 are the parameters
def foo_method(param1, param2):
    .......
end

while calling the method, arg1 and arg2 are the arguments
foo_method(arg1, arg2)

No comments:

Post a Comment