yes, arguably. But no more so than the usual ways of doing this, hash[:foo][:bar][:baz]
or (more safely) hash[:foo] && hash[:foo][:bar] && hash[:foo][:bar][:baz]
. dig
is a shortcut for these.
I do think you are on the right track that using nested hashes to pass around complex data is akin to a violation of the Law of Demeter, whether using dig or not, it's doing the kind of thing the Law of Demeter is meant against. In the sense that your code needs to know about the structure of the hash, instead of just calling methods with clear API's. One could then say that dig
is taking a kind of violation of the LoD that was being oftenly done -- and making it even easier to do, which a purist could say was a bad idea.
But in practical programming, in ruby at least, the Law of Demeter is more of a general good idea to consider than an actual Law to be followed slavishly.
And one could also argue that in some ways dig
avoids the LoD violations that were happening without it. Technically when using dig
you are no longer violating the LoD, as you are now just calling one method (the one dig
call) on the object you have a direct reference to. I don't think that technicality matters too much, you are really doing the same thing either way.