Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Hash with dot notations
class HashWithDotNotation < Hash
def initialize(constructor = {})
if constructor.is_a?(Hash)
super()
self.replace(constructor)
else
super(constructor)
end
end
def method_missing_with_dot_notation_lookup(*args)
if self.has_key?(args[0])
rvalue = self.fetch(args[0])
rvalue = rvalue.with_dot_notation if rvalue.is_a?(Hash)
rvalue.map!{|e| e.is_a?(Hash) ? e.with_dot_notation : e } if rvalue.is_a?(Array)
rvalue
else
self.method_missing_with_out_dot_notation_lookup(*args)
end
end
alias_method_chain :method_missing, :dot_notation_lookup
end
class Hash #:nodoc:
def with_dot_notation
hash = HashWithDotNotation.new(self)
hash.default = self.default
hash
end
def with_dot_notation!
self.replace self.with_dot_notation
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.