Take a look at the Configatron gem. Em 27/07/2014 17:02, "James Coleman" <jtc...@gmail.com> escreveu:
> The andand gem will allow you to write code like: > > hash.andand[:key].andand[:key2] > > where anything on a nil object returns a proxy that accepts any method and > returns nil. This is far safer than what you propose as it won't affect > anyone. > > In general though, while this may seem convenient, it makes reasoning > about code significantly more difficult. The more code you write, the more > I believe that you find that we need *more* explicit handling of nil not > less. > > > On Sun, Jul 27, 2014 at 1:52 PM, Sergio Campamá <sergiocamp...@gmail.com> > wrote: > >> I think a better approach is >> >> return hash && hash[:data] && hash[:data][:details] && >> hash[:data][:details][:id] >> >> That will return the value or nil if the chain was broken at any >> point. I know it's not the same, but much less code than the example. >> -------------------------------------- >> Sergio Campamá >> sergiocamp...@gmail.com >> >> >> >> On Sun, Jul 27, 2014 at 10:48 AM, Steve Klabnik <st...@steveklabnik.com> >> wrote: >> > This has a very large potential to break a very, very large amount of >> code. >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups "Ruby on Rails: Core" group. >> > To unsubscribe from this group and stop receiving emails from it, send >> an email to rubyonrails-core+unsubscr...@googlegroups.com. >> > To post to this group, send email to rubyonrails-core@googlegroups.com. >> > Visit this group at http://groups.google.com/group/rubyonrails-core. >> > For more options, visit https://groups.google.com/d/optout. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Core" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to rubyonrails-core+unsubscr...@googlegroups.com. >> To post to this group, send email to rubyonrails-core@googlegroups.com. >> Visit this group at http://groups.google.com/group/rubyonrails-core. >> For more options, visit https://groups.google.com/d/optout. >> > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-core+unsubscr...@googlegroups.com. > To post to this group, send email to rubyonrails-core@googlegroups.com. > Visit this group at http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.