Created
June 23, 2015 23:20
-
-
Save morhekil/89a27493811e02b3bf1b to your computer and use it in GitHub Desktop.
Destructuring Ruby hashes with named parameters and anonymous splat
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
def stuff | |
yield action: 'Boom', schedule: '7PM', color: :red, debug: true | |
end | |
# When a hash is yielded to a block, we can used named arguments to | |
# capture the keys we want, and an anonymous splat to ignore | |
# everything else | |
stuff { |action:, schedule:, **| p "Doing #{action} at #{schedule}" } | |
# | |
# > ruby ./anonsplat.rb | |
# Doing Boom at 7PM | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment