2012-06-19 @ 12:00

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class HashHash < Hash
  def initialize
    super { |h,k| h[k] = HashHash.new }
  end

  def method_missing(key, *args)
    ks = key.to_s
    if ks[-1..-1] == "=" then
      self[ks[0..-2].intern] = args.first
    else
      self[key]
    end
  end
end

conf = HashHash.new

conf.windows.toolbar.x = 250
p conf.windows.toolbar.x # => 250
p conf                   # => {:windows=>{:toolbar=>{:x=>250}}}
« go back