【问题标题】:What is ^ in Ruby Syntax? (Shopify scripts example)Ruby 语法中的 ^ 是什么? (Shopify 脚本示例)
【发布时间】: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

有人有什么主意吗?感谢您的任何输入

【问题讨论】:

    标签: ruby shopify editor


    【解决方案1】:

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

    【讨论】:

    • @invert 看起来像一个布尔值,所以它是一个布尔异或,而不是按位。
    猜你喜欢
    • 1970-01-01
    • 2011-12-24
    • 2015-11-27
    • 1970-01-01
    • 2011-01-20
    • 2016-01-21
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多