From fa86026a99b36512d1cbefd79b1b7b20986fb734 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sun, 15 Nov 2015 05:15:20 +0900 Subject: move Hash comparison methods to mruby-hash-ext gem --- mrblib/hash.rb | 96 ---------------------------------------------------------- 1 file changed, 96 deletions(-) (limited to 'mrblib') diff --git a/mrblib/hash.rb b/mrblib/hash.rb index 8e56fca81..e3e709070 100644 --- a/mrblib/hash.rb +++ b/mrblib/hash.rb @@ -346,102 +346,6 @@ class Hash h.each_key{|k| self[k] = h[k]} self end - - ## - # call-seq: - # hash < other -> true or false - # - # Returns true if hash is subset of - # other. - # - # h1 = {a:1, b:2} - # h2 = {a:1, b:2, c:3} - # h1 < h2 #=> true - # h2 < h1 #=> false - # h1 < h1 #=> false - # - def <(hash) - begin - hash = hash.to_hash - rescue NoMethodError - raise TypeError, "can't convert #{hash.class} to Hash" - end - size < hash.size and all? {|key, val| - hash.key?(key) and hash[key] == val - } - end - - ## - # call-seq: - # hash <= other -> true or false - # - # Returns true if hash is subset of - # other or equals to other. - # - # h1 = {a:1, b:2} - # h2 = {a:1, b:2, c:3} - # h1 <= h2 #=> true - # h2 <= h1 #=> false - # h1 <= h1 #=> true - # - def <=(hash) - begin - hash = hash.to_hash - rescue NoMethodError - raise TypeError, "can't convert #{hash.class} to Hash" - end - size <= hash.size and all? {|key, val| - hash.key?(key) and hash[key] == val - } - end - - ## - # call-seq: - # hash > other -> true or false - # - # Returns true if other is subset of - # hash. - # - # h1 = {a:1, b:2} - # h2 = {a:1, b:2, c:3} - # h1 > h2 #=> false - # h2 > h1 #=> true - # h1 > h1 #=> false - # - def >(hash) - begin - hash = hash.to_hash - rescue NoMethodError - raise TypeError, "can't convert #{hash.class} to Hash" - end - size > hash.size and hash.all? {|key, val| - key?(key) and self[key] == val - } - end - - ## - # call-seq: - # hash >= other -> true or false - # - # Returns true if other is subset of - # hash or equals to hash. - # - # h1 = {a:1, b:2} - # h2 = {a:1, b:2, c:3} - # h1 >= h2 #=> false - # h2 >= h1 #=> true - # h1 >= h1 #=> true - # - def >=(hash) - begin - hash = hash.to_hash - rescue NoMethodError - raise TypeError, "can't convert #{hash.class} to Hash" - end - size >= hash.size and hash.all? {|key, val| - key?(key) and self[key] == val - } - end end ## -- cgit v1.2.3