How to minimize nested if statements? (Ruby) -


I think I often talk about this type of ruby ​​code:

  If the person is the person then Shirt if person.shirt.sleeve ... and end   

.. which I do to avoid NoMethodErrors I am thinking that if by any means I can make it fall in a row, without clearly clear

  if person & amp; person. Shirt & amp; amp; Actually, I want to make my code more compact.   

Inside those IFS, you want to do something with the sleeves, Isn't it?

Rail is a good helper, it all goes well, and zero gives value otherwise, in this example, if person.shirt Or even if the person is zero, the effort will also return as zero.

  If sleeve   

You can use gem for vanilla ruby ​​which provides similar functionality.

  if sleeves = person.and.shirt.andAnd. # End your content    

Comments