在这里瞎了......我无法理解为什么这两个字符串不相等..当我puts
他们到终端时他们都是类string
当我只是比较它们的输出时是平等的。但不知何故,在我的代码中他们不是......我无法弄清楚原因。
这是我的Ruby代码:
def prep_for_duplicate_webhook
@redis_cart = Redis.new
cart_stamp_saved = @redis_cart.get("cart_stamp_saved")
if cart_stamp_saved.nil?
cart_stamp_saved = {}
cart_stamp_saved[:token] = cart_params['token']
cart_stamp_saved[:updated_at] = cart_params['updated_at']
@redis_cart.set("cart_stamp_saved", cart_stamp_saved.to_json)
end
@cart_stamp_incoming = {}
@cart_stamp_incoming["token"] = cart_params['token']
@cart_stamp_incoming["updated_at"] = cart_params['updated_at']
end
def duplicate_webhook?
prep_for_duplicate_webhook
@cart_stamp_saved = redis_cart.get("cart_stamp_saved")
cart_stamp_saved == cart_stamp_incoming.to_json
end
然后我正在比较的哈希就是这两个:
cart_stamp_saved = {"token"=>"4a093432ba5c430dd545b16c0e89f187",
"updated_at"=>"2017-02-17T15:27:22.923Z"}
cart_stamp_incoming= {"token"=>"4a093432ba5c430dd545b16c0e89f187",
"updated_at"=>"2017-02-17T15:27:22.923Z"}
如果我只是将上述内容复制并粘贴到新页面中,并执行此操作,则回复为true
pp cart_stamp_saved == cart_stamp_incoming.to_json
我错过了什么?