Last active
September 8, 2022 19:59
-
-
Save tjaved573/fa13d1ee1fc65ace6dc217d1b0dbd623 to your computer and use it in GitHub Desktop.
splat_operator.rb
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
# single splat operator converts all arguments into an array. | |
# double splat operator converts all arguments into a hash | |
# order of arguments: | |
#// required -> optional -> variable -> keyword (use hash syntax) | |
def dubSplat (*c, **d) | |
p c | |
p d | |
end | |
dubSplat("ali", "mir" , bro1:["hashim"], bro2:["taimoor"], age: 23, school:"Purdue" ) | |
#key difference | |
dubSplat("ali": "mir" , bro1:["hashim"], bro2:["taimoor"], age: 23, school:"Purdue" ) | |
#! for Joining 2 hashes using double splat operator | |
keyword_options = { | |
keywords: ['Single Splat operator in Ruby', 'How to gobble up values in Ruby'] | |
} | |
site_options = { | |
site_name: 'Ruby Splat Operator', | |
site_url: 'https://rubyinrails.com' | |
} | |
all_options = { **keyword_options, **site_options } | |
p all_options |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment