After seeing like 10 version of people and their Table classes, decided to simply this. Maybe I am just under thinking Tables, but I think people are over complicating them. So here is what I just came up with:
It doesn't do anything special at all. It's just a wrapper of the Hash instead of an array. Supports unlimited dimensions (actually, all it does create a bunch of keys).
- class Table
- Default = 0
- attr_reader :default
- def initialize(default = Default)
- @data = {}
- @data.default = default
- end
- def default=(default)
- @data.default = default
- end
- def [](*args)
- return @data[args]
- end
- def []=(*args)
- v = args.pop
- @data[args] = v
- end
- def each(&block)
- @data.each(&block)
- end
- def each_value(&block)
- @data.each_value(&block)
- end
- end
Expand to see the code.
It doesn't do anything special at all. It's just a wrapper of the Hash instead of an array. Supports unlimited dimensions (actually, all it does create a bunch of keys).