Possible Duplicate:
What does ||= (or equals) mean in Ruby?
It's hard to search this in Google because it is a symbol, not text.
What does ||=
stand for?
And how does it work?
a ||= b is a conditional assignment operator. It means: if a is undefined or falsey, then evaluate b and set a to the result. Otherwise (if a is defined and evaluates to truthy), then b is not evaluated, and no assignment takes place.
Triple Equals Operator (More Than Equality) Our last operator today is going to be about the triple equals operator ( === ). This one is also a method, and it appears even in places where you wouldn't expect it to. Ruby is calling the === method here on the class.
An operator is a symbol that represents an operation to be performed with one or more operand. Operators are the foundation of any programming language. Operators allow us to perform different kinds of operations on operands. There are different types of operators used in Ruby as follows: Arithmetic Operators.
Ruby Arithmetic OperatorsSubtraction − Subtracts right hand operand from left hand operand. Multiplication − Multiplies values on either side of the operator. Division − Divides left hand operand by right hand operand. Modulus − Divides left hand operand by right hand operand and returns remainder.
It assigns a value if not already assigned. Like this:
a = nil a ||= 1 a = 1 a ||= 2
In the first example, a will be set to 1. In the second one, a will still be 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With