Sha256: 5ad454dcd7e0f07d329cd380be958243f69e6b8012df0e0ee2ed1d98c85cc54e

Contents?: true

Size: 837 Bytes

Versions: 1

Compression:

Stored size: 837 Bytes

Contents

require 'nano/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

1 entries across 1 versions & 1 rubygems

Version Path
facets-0.9.0 lib/nano/hash/assert_has_only_keys.rb