Skip to content

Commit 756129b

Browse files
dvandersluisbbatsov
authored andcommitted
Add section on merging keyword arguments.
1 parent 0d6d65c commit 756129b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,6 +3190,19 @@ def some_method(bar: false)
31903190
end
31913191
----
31923192

3193+
=== Merging Keyword Arguments [[merging-keyword-arguments]]
3194+
3195+
When passing an existing hash as keyword arguments, add additional arguments directly rather than using `merge`.
3196+
3197+
[source,ruby]
3198+
----
3199+
# bad
3200+
some_method(**opts.merge(foo: true))
3201+
3202+
# good
3203+
some_method(**opts, foo: true)
3204+
----
3205+
31933206
=== Arguments Forwarding [[arguments-forwarding]]
31943207

31953208
Use Ruby 2.7's arguments forwarding.

0 commit comments

Comments
 (0)