Hmm, let's talk about ||
If in my previous post '&&' is used like a 'then', this '||' is the opposite of that.
Look at example below
Code:
#==============================================================================
# ** Sprite
#------------------------------------------------------------------------------
# A sprite class for bitmap processing.
#==============================================================================
class Sprite
alias anti_dispose_error_alias dispose
def dispose
disposed? || anti_dispose_error_alias # <<<<
end
end
The code above is fixes to prevent disposed sprite to throws an error if disposed again.
Normally when Sprite is disposed twice, an error would pop up saying "Sprite was disposed.". That code is prevents that.
I believe you already know about alias so I won't touch it.
Let's look at
disposed? || anti_dispose_error_alias. The method
disposed? is a method in class Sprite to check if Sprite already disposed or not, the method returns
true if already disposed or
false if haven't.
It's just like asking the sprite : "Hey sprite, have you already disposed?"
Moving on, let's talk about '||' behavior, as you probably guessed, it's opposite of '&&'.
If '&&' will check the next sentence only if previous one are
true, the '||' will check the next sentence only if previous one are
false or
nil!
So based on that behavior if sprite is already disposed, it will not check
anti_dispose_error_alias.
false || false || false || true
|| false || true || ......
As you see, the program will stop reading when the condition are true.
By the way:
|| = or
disposed? || anti_dispose_error_alias
disposed? or anti_dispose_error_alias
Those two are same things.