Good Ruby Idiom: and/or operators

Any tutorial and book will teach you there are two sets of similar operators in Ruby: &&/|| vsand/or (and also &/| for bit operations, but that’s not the case today). But typical tutorial will not provide further explanation why we need both of those pairs.

Some of tutorials and blog posts about this matter even go as far as explicit recommendations never useand/or, because && and || is enough for all reasonable cases, and because and/or provide only confusion. They would typically warn you about and’s lower precedence than =, but nobody will tell you how this can and should be useful.


Good Ruby Idiom: and/or operators #ruby #rubydeveloper #rubyonrails https://rubyonrails.ba/single/good-ruby-idiom-andor-operators

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles