Introduce Named Parameter

The parameters in a method call cannot easily be deduced from the name of the method you are calling.

Convert the parameter list into a Hash, and use the keys of the Hash as names for the parameters.

SearchCriteria.new(5, 8, "0201485672")
  

image/svg+xml

SearchCriteria.new(:author_id => 5, :publisher_id => 8, :isbn =>"0201485672")

inverse of Remove Named Parameter

Additions

Martin Fowler

19 Nov 2013

With version 2.0, the Ruby language now has built-in support for named parameters. These can be used instead of hashes, with the advantage of explicitly defining the parameters in the method signature.