Last active
August 29, 2015 14:03
-
-
Save guilleiguaran/80b68fecc4b69e9b3823 to your computer and use it in GitHub Desktop.
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
class Hash | |
# Allow accessing to hash elements using full key path separated by comma. | |
# | |
# hash = {"flash" => {"error" => {"message" => "User type is invalid"}}} | |
# hash.param("flash.error.message") | |
# # => "User type is invalid" | |
# | |
def param(key) | |
return self[key] unless key.is_a?(String) && key.include?(".") | |
key.to_s.split('.').inject(self) do |param, key| | |
return unless param | |
param[key] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment