【发布时间】:2022-11-23 03:25:15
【问题描述】:
我正在解码另一个开发人员编写的 Shopify 脚本(用于购物车折扣),它包含一些我以前从未见过的 Ruby 语法。拉起谷歌搜索我没有找到在下面的代码中使用“^”的解释,特别是在这些行中:
返回@invert^((@tags & customer_tags).length > 0) 返回@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
有人有什么主意吗?感谢您的任何输入
【问题讨论】: