Created
April 8, 2015 21:30
-
-
Save crimsonknave/3165cfa761bee08ae12e to your computer and use it in GitHub Desktop.
Example of a pythonesque case using a hash with lambdas for values
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 parse_options(opts) | |
parsed = {} | |
opts.each do |option| | |
parsed.merge! option_handlers[option].call option | |
end | |
parsed | |
end | |
def option_handlers | |
{ | |
'option1' => ->(key) { { key => 'option1 result' } } | |
} | |
end | |
puts parse_options(['option1']).inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment