Huum, Interesting from the below code I got the taste :
a = [2,3,4]
=> [2, 3, 4]
a>>=[2,1,4,6]
b ||= [2,33]
=> [2, 33]
b ||= [21,33]
=> [2, 33]
From the above code it is clear that "||=" operators set the variable
conditionally. Condition is like that if the variable is set to "false
or nil" then set it or return it's already set value.
=> [2, 3, 4]
a |= [2,1,4,6]
=> [2, 3, 4, 1, 6]
a = [1,2,3]
=> [1, 2, 3]
a |= [4,5]
=> [1, 2, 3, 4, 5]
a |= [4,5,6]
=> [1, 2, 3, 4, 5, 6]
From the above code I can say that "|=" operator performing kind of
concatenation and if delicates then remove it away.
If any wrong logic I said here, forgive me and correct me please.
I think I have something even better: advice how to find out yourself.
Fire up IRB and then start experimenting. It's best to start from
simple expressions, so first for different combinations of a and b do
a && b
Look at the result. Then do
a &&= b
a ||= b
Reason about what you see. If unsure, do more tests.
Kind regards
robert
···
On Fri, Feb 22, 2013 at 11:51 PM, Xavier R. <lists@ruby-forum.com> wrote:
Hans Mackowiak wrote in post #1098517:
is not nil or false
if
p "like true"
else
p "like false"
end
guess what this lines will output?
got the point. Could you give me a valid example of "&&=" ?