【发布时间】:2014-06-01 21:26:58
【问题描述】:
如何判断 Ruby 哈希是否是(或包含)另一个哈希的子集?
例如:
hash = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7}
hash.include_hash?({}) # true
hash.include_hash?({f: 6, c: 3}) # true
hash.include_hash?({f: 6, c: 1}) # false
【问题讨论】:
-
马特,你似乎被授予了embarrassment of riches。 (英语是第二语言的人的链接。)在 SO 上获得四分之四的高质量答案非常罕见。