Trying to learn Ruby I ran into this kind of syntax.... Can anyone explain me what it means?
a = nil if b.nonzero?
nonzero? : Returns self if num is not zero, nil otherwise.
And thus does not return a boolean
Values in ruby are truthy and falsey. That is, if a value is not nil, or false, it is true. So if you have a function that returns 1, you can use that in a boolean expression some_function && true would resolve true.
Likewise, if it returned nil, some_function && true would return false.
There's a detailed and in depth explanation here: https://gist.github.com/jfarmer/2647362
nilis falsy value, so ifbis nonzero, theifcondition will evaluate to equivalent tofalse.Returns selfmeans the value ofbwill be returned if its non-zeronil, the modifier conditionalif, a local variable dereference and a method call. Which one is unknown to you?