Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have run to the following code and I have no idea what it does. Why do they use = to compare values or are they assigning values and checking if the value is true after being assigned?
=
if value = (key rescue nil) .. end
value
This is equivalent to:
value = key rescue nil if value .. end
or
value = begin key rescue nil end if value .. end
Remember nil and false are the only two objects that are falsey in ruby and since value here could be nil, that if statement could return false.
nil
false
falsey
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
valueand then checking if it's truthy.