Created
March 15, 2023 05:30
-
-
Save tigris/79c4fc030baf7d61e45d9e8cb3ee8016 to your computer and use it in GitHub Desktop.
kwargs and splats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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