Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Recursive lambda that symbolize keys of a Hash
Symbolize = (l = ->(h) { h.inject({}) { |m, (k,v)| m[(String === k ? k.to_sym : k)] = (Hash === v ? l.(v) : v); m }})
# Example:
hash = { 'task' => { 'description' => 'Ab@ @example @cd', 'target' => { 'label' => 'cd' } } }
Symbolize.(hash)
# => { :task => { :description => "Ab@ @example @cd", :target => { :label => "cd" } } }
@alejandrobabio

This comment has been minimized.

Copy link
Owner Author

alejandrobabio commented Nov 29, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.