Named parameters: Difference between revisions

→‎{{header|Ruby}}: removed Ruby 1.8 version
(Add F#)
(→‎{{header|Ruby}}: removed Ruby 1.8 version)
Line 1,819:
 
example(grill: "lamb kebab", bar: 3.14)</syntaxhighlight>
 
Ruby 1.8 and older versions can do the same, but must use the old syntax <code>:name => value</code>.
 
<syntaxhighlight lang="ruby">def example(opts = {})
defaults = {:foo => 0, :bar => 1, :grill => "pork chops"}
opts = defaults.merge(opts)
printf("foo is %s, bar is %s, and grill is %s\n",
opts[:foo], opts[:bar], opts[:grill])
end
 
example(:grill => "lamb kebab", :bar => 3.14)</syntaxhighlight>
 
{{omit from|Rust}}
1,149

edits