"Christoph Rippel" <crippel / primenet.com> writes: > > From: nosuzuki / e-mail.ne.jp [mailto:nosuzuki / e-mail.ne.jp]On Behalf Of > [..] > > h = HashMD.new > > h['a']['b']['c'] = 'xxx' #=> {"a" => {"b" => {"c" => "xxx"}}} > Hi, > > > why don't you write > > h = {'a'=>{'b'=>{'c'=>'xxx'}}} > > it creates what you want and you actually type less. > > Christoph > > [..] You only type less if you're doing it this way *once*. If your program is filled with things like this ... h = {'a'=>{'b'=>{'c'=>'xxx'}}} .. you end up typing a lot more than if you instantiate one `HashMD' object and then use lots of constructs like this: h['a']['b']['c'] = 'xxx' However, in my opinion, saving a few keystrokes isn't very important at all. To me, the advantage of the latter form is that it's much easier to read, understand, and maintain. Also, to me, a good idea would be to have some sort of mixin that can be included in Hash that can add a `get' and `set' method that look something like this: h.get('a','b','c') h.set('a','b','c','xxx') The `get' method would return nil (or perhaps throw an exception) if a non-existent node is being referenced; and the `set' method would create the internal structure as needed. This construct would still be easy to read, understand, and maintain. And I believe that it should be relatively simple to write and use. Over the next few days I'll give it a shot, and I'll post my results here. -- Lloyd Zusman ljz / asfast.com