Skip to content

Instantly share code, notes, and snippets.

@tigris
Created March 15, 2023 05:30
Show Gist options
  • Save tigris/79c4fc030baf7d61e45d9e8cb3ee8016 to your computer and use it in GitHub Desktop.
Save tigris/79c4fc030baf7d61e45d9e8cb3ee8016 to your computer and use it in GitHub Desktop.
kwargs and splats
#!/usr/bin/env ruby
##### KWARGS
def kwargs(foo:, bar:)
puts "foo: #{foo}"
puts "bar: #{bar}"
end
puts "==== kwargs test ===="
kwargs(foo: true, bar: false)
args = { foo: true, bar: false }
kwargs(**args)
##### SPLAT
def splat(foo, bar)
puts "foo: #{foo}"
puts "bar: #{bar}"
end
puts "==== splat test ===="
splat(true, false)
args = [ true, false ]
splat(*args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment