Module: Hashie::Extensions::Structure

Defined in:
lib/hashie/extensions/structure.rb

Overview

The Structure extension provides facilities for declaring properties that a Hash can have. This provides for the creation of structures that still behave like hashes but do not allow setting non-allowed keys.

Examples:

class RestrictedHash < Hash
  include Hashie::Extensions::MergeInitializer
  include Hashie::Extensions::Structure

  key :first
  key :second, :default => 'foo'
end

h = RestrictedHash.new(:first => 1)
h[:first]  # => 1
h[:second] # => 'foo'
h[:third]  # => ArgumentError

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object


23
24
25
26
27
28
# File 'lib/hashie/extensions/structure.rb', line 23

def self.included(base)
  base.extend ClassMethods
  base.class_eval do
    @permitted_keys = superclass.permitted_keys if superclass.respond_to?(:permitted_keys)
  end
end