class MacHash attr_accessor :hash def initialize hash self.hash = hash.symbolize_keys end def method_missing(method, *args) new_hash = hash[method] new_hash.is_a?(Hash) ? MacHash.new(new_hash) : new_hash end endAnd now we can test it:
hc = HashClass.new({:a => {:b => 10}, :c => [1, 2, 3]}) hc.a.b => 10 hc.c => [1, 2, 3]