class Hash # Returns true if the hash contains # _only_ the given keys, otherwise false. # # h = { :a => 1, :b => 2 } # h.has_only_keys?( :a, :b ) #=> true # h.has_only_keys?( :a ) #=> false # def has_only_keys?(*check_keys) unknown_keys = self.keys - check_keys return unknown_keys.empty? end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TCHash < Test::Unit::TestCase def test_has_only_keys? assert( { :a=>1,:b=>2,:c=>3 }.has_only_keys?(:a,:b,:c) ) assert( ! { :a=>1,:b=>2,:c=>3 }.has_only_keys?(:a,:b) ) end end =end