Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
6
Task/Named-parameters/Ruby/named-parameters-1.rb
Normal file
6
Task/Named-parameters/Ruby/named-parameters-1.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
def example(foo: 0, bar: 1, grill: "pork chops")
|
||||
puts "foo is #{foo}, bar is #{bar}, and grill is #{grill}"
|
||||
end
|
||||
|
||||
# Note that :foo is omitted and :grill precedes :bar
|
||||
example(grill: "lamb kebab", bar: 3.14)
|
||||
11
Task/Named-parameters/Ruby/named-parameters-2.rb
Normal file
11
Task/Named-parameters/Ruby/named-parameters-2.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
def example(opts = {})
|
||||
# Hash#merge raises TypeError if _opts_ is not a Hash.
|
||||
# Nothing checks if _opts_ contains unknown keys.
|
||||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue