What looks like one operator in the middle (&.!=
) is actually 1 operator and 1 method call : &.
followed by !=
with :click
as argument:
action &. != :click
It checks if action
is not nil
but distinct from :click
:
action = nil
action&.!=:click
# => nil
action = :not_click
action&.!=:click
# => true
action = :click
action&.!=:click
# => false
action = false
action&.!=:click
# => true
It's an abusive way to use &.
in my humble opinion. &.
is called a "safe navigation operator", because it prevents you from calling undefined methods on nil
objects.
!=
is defined for any object though, so there's nothing safe about using &.
before !=
.
You could write :
!(action.nil? || action == :click)
or
!action.nil? && action != :click
or even:
![nil, :click].include?(action)