Sha256: 7530dadb928dc93f1bc82d964922add998286243530463d2fc35baecf362ccb8

Contents?: true

Size: 838 Bytes

Versions: 22

Compression:

Stored size: 838 Bytes

Contents

require 'facet/hash/has_only_keys'

class Hash

  # Returns true is hash has only then given keys,
  # otherwise throws an ArgumentError.
  #
  #   h = { :a => 1, :b => 2 }
  #   h.assert_has_only_keys( :a, :b )   #=> true
  #   h.assert_has_only_keys( :a )       #=> ArgumentError
  #
  def assert_has_only_keys(*check_keys)
    raise(ArgumentError, "has unexpected key(s)") unless has_only_keys?(*check_keys)
  end

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCHash < Test::Unit::TestCase

    def test_assert_has_only_keys
      assert_nothing_raised {  { :a=>1,:b=>2,:c=>3 }.assert_has_only_keys(:a,:b,:c) }
      assert_raises( ArgumentError ) { { :a=>1,:b=>2,:c=>3 }.assert_has_only_keys(:a,:b) }
    end

  end

=end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
facets-1.0.0 lib/facet/hash/assert_has_only_keys.rb
facets-1.0.3 packages/core/lib/facet/hash/assert_has_only_keys.rb
facets-1.3.0 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.1.0 lib/facet/hash/assert_has_only_keys.rb
facets-1.2.0 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.2.1 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.3.2 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.3.1 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.3.3 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.4.1 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.4.0 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.4.2 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.4.3 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.4.5 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.4.4 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.7.38 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.7.0 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.7.30 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.7.46 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.8.0 lib/facets/core/hash/assert_has_only_keys.rb