Skip to content

Instantly share code, notes, and snippets.

@midwire
Created August 19, 2022 18:08
Show Gist options
  • Save midwire/996fa6e23cd9c57b99a877f37de4af3f to your computer and use it in GitHub Desktop.
Save midwire/996fa6e23cd9c57b99a877f37de4af3f to your computer and use it in GitHub Desktop.
[Ruby Splat and Double-Splat] #ruby
def foo(a, *b, **c)
[a, b, c]
end
> foo 10
=> [10, [], {}]
> foo 10, 20, 30
=> [10, [20, 30], {}]
> foo 10, 20, 30, d: 40, e: 50
=> [10, [20, 30], {:d=>40, :e=>50}]
> foo 10, d: 40, e: 50
=> [10, [], {:d=>40, :e=>50}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment