Module Hashie::Extensions::StrictKeyAccess
In: lib/hashie/extensions/strict_key_access.rb

SRP: This extension will fail an error whenever a key is accessed that does not exist in the hash.

  EXAMPLE:

    class StrictKeyAccessHash < Hash
      include Hashie::Extensions::StrictKeyAccess
    end

    >> hash = StrictKeyAccessHash[foo: "bar"]
    => {:foo=>"bar"}
    >> hash[:foo]
    => "bar"
    >> hash[:cow]
      KeyError: key not found: :cow

NOTE: For googlers coming from Python to Ruby, this extension makes a Hash behave more like a "Dictionary".

Methods

[]   default   default=   default_proc   default_proc=   key  

Classes and Modules

Class Hashie::Extensions::StrictKeyAccess::DefaultError

Public Instance methods

NOTE: Defaults don‘t make any sense with a StrictKeyAccess. NOTE: When key lookup fails a KeyError is raised.

Normal:

    >> a = Hash.new(123)
    => {}
    >> a["noes"]
    => 123

With StrictKeyAccess:

    >> a = StrictKeyAccessHash.new(123)
    => {}
    >> a["noes"]
      KeyError: key not found: "noes"

[Validate]