Created
February 2, 2012 16:25
-
-
Save maxjustus/1724372 to your computer and use it in GitHub Desktop.
Hash with symbol to string lookup
This file contains hidden or 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
opts = {'meep' => 'feep', :derp => 'herp'} | |
opts.default_proc = ->(h,k) { h.fetch(k.to_s) { nil } } | |
opts[:meep] | |
=> 'feep' | |
opts['derp'] | |
=> 'herp' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment