#try - Rails

In a discussion by Avdi Grimm about how to access values in nested hashes, he ends up arguing against #try, and he weighs the pros and cons of other ways of accessing hash values.

He also wrote an article about #fetch. There'd be an exception raised if the key you pass to #fetch is missing, and you didn't supply a default value. He points out that that may be a good thing sometimes. Read the official documentation for fetch.

Aaaand finally, he discusses #try in the context of chaining objects in another article. If you only read one article, I'd suggest this one. He discusses the Law of Demeter and structural coupling. He also shows why chaining methods is okay sometimes. The comment thread is very good, too—Ryan Bates and Michael Feathers chime in.

Michael Stalker

Michael is a former SciMed developer.