How do I compare two hashes?

前端 未结 14 1570
粉色の甜心
粉色の甜心 2020-11-30 00:06

I am trying to compare two Ruby Hashes using the following code:

#!/usr/bin/env ruby

require \"yaml\"
require \"active_support\"

file1 = YAML::load(File.op         


        
14条回答
  •  悲&欢浪女
    2020-11-30 00:50

    what about convert both hash to_json and compare as string? but keeping in mind that

    require "json"
    h1 = {a: 20}
    h2 = {a: "20"}
    
    h1.to_json==h1.to_json
    => true
    h1.to_json==h2.to_json
    => false
    

提交回复
热议问题