Skip to content

Instantly share code, notes, and snippets.

@crimsonknave
Created April 8, 2015 21:30
Show Gist options
  • Save crimsonknave/3165cfa761bee08ae12e to your computer and use it in GitHub Desktop.
Save crimsonknave/3165cfa761bee08ae12e to your computer and use it in GitHub Desktop.
Example of a pythonesque case using a hash with lambdas for values
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