Adam Cuppy
Posted on December 18, 2019
For whatever reason, I love writing Ruby's or/equal operator (||=
). Said in human-speak, if the variable on the left is null
then assign it the value on the right; otherwise, leave the variable on the left as is: @left ||= 'right'
Simplicity
The concept of or/equal exists throughout life, "Is the oven on? No, then set it to 350 degrees." We get it. The flow is natural.
Interpretability
The syntax is easy to parse. If you're familiar with ||
meaning or and =
meaning should now equal then combining them leads down a logical path towards or should now equal. Neat!
What's your favorite programming expression/method/operator?
Post and example. Why do you love writing it?
π πͺ π
π©
Adam Cuppy
Posted on December 18, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.