Ruby语法中的^是什么?(Shopify脚本示例)



我正在解码一个由另一个开发人员编写的Shopify脚本(用于购物车折扣),它包含了一些我以前从未见过的Ruby语法。在谷歌上搜索一下,我没有找到"^"这个词背后的解释。在下面的代码中,特别是在这些行中:

return @invert ^ ((@tags & customer_tags).length > 0)
return @invert ^ ((@tags & customer_tags).length > 0)

见下文:

class CustomerTagQualifier < Qualifier
def initialize(match_type, match_condition, tags)
@match_condition = match_condition
@invert = match_type == :does_not
@tags = tags.map(&:downcase)
end

def match?(cart, selector = nil)
return true if cart.customer.nil? && @invert
return false if cart.customer.nil?
customer_tags = cart.customer.tags.to_a.map(&:downcase)
case @match_condition
when :match
return @invert ^ ((@tags & customer_tags).length > 0)
else
return @invert ^ partial_match(@match_condition, customer_tags, @tags)
end
end
end

有人知道吗?谢谢你的输入

这是一个布尔异或运算符。https://en.wikipedia.org/wiki/Exclusive_or

最新更新