Module: Hashie::Extensions::IgnoreUndeclared

### Home Classes Methods

### In Files

- lib/hashie/extensions/ignore_undeclared.rb

### Methods

- #initialize_attributes
- #property_exists?

### Class/Module Index

Quicksearch

- Hashie
- Hashie::Clash
- Hashie::Clash::ChainError
- Hashie::CoercionError
- Hashie::Dash
- Hashie::Extensions
- Hashie::Extensions::Coercion
- Hashie::Extensions::Coercion::ClassMethods
- Hashie::Extensions::Coercion::InstanceMethods
- Hashie::Extensions::Dash
- Hashie::Extensions::Dash::IndifferentAccess
- Hashie::Extensions::Dash::IndifferentAccess::ClassMethods
- Hashie::Extensions::DeepFetch
- Hashie::Extensions::DeepFetch::UndefinedPathError
- Hashie::Extensions::DeepFind
- Hashie::Extensions::DeepMerge
- Hashie::Extensions::IgnoreUndeclared
- Hashie::Extensions::IndifferentAccess
- Hashie::Extensions::KeyConversion
- Hashie::Extensions::Mash
- Hashie::Extensions::Mash::SafeAssignment
- Hashie::Extensions::MergeInitializer
- Hashie::Extensions::MethodAccess
- Hashie::Extensions::MethodAccessWithOverride
- Hashie::Extensions::MethodOverridingWriter
- Hashie::Extensions::MethodQuery
- Hashie::Extensions::MethodReader
- Hashie::Extensions::MethodWriter
- Hashie::Extensions::Parsers
- Hashie::Extensions::Parsers::YamlErbParser
- Hashie::Extensions::PrettyInspect
- Hashie::Extensions::StringifyKeys
- Hashie::Extensions::StringifyKeys::ClassMethods
- Hashie::Extensions::SymbolizeKeys
- Hashie::Extensions::SymbolizeKeys::ClassMethods
- Hashie::Hash
- Hashie::Mash
- Hashie::Rash
- Hashie::Trash

No matching classes.

# Hashie::Extensions::IgnoreUndeclared

IgnoreUndeclared is a simple mixin that silently ignores undeclared properties on initialization instead of raising an error. This is useful when using a Trash to capture a subset of a larger hash.

Note that attempting to retrieve or set an undeclared property will still raise a NoMethodError, even if a value for that property was provided at initialization.

@example

    class Person < Trash
      include Hashie::Extensions::IgnoreUndeclared

      property :first_name
      property :last_name
    end

    user_data = {
       :first_name => 'Freddy',
       :last_name => 'Nostrils',
       :email => 'freddy@example.com'
    }

    p = Person.new(user_data) # 'email' is silently ignored

    p.first_name # => 'Freddy'
    p.last_name  # => 'Nostrils'
    p.email      # => NoMethodError

### Public Instance Methods

initialize_attributes(attributes) click to toggle source

    # File lib/hashie/extensions/ignore_undeclared.rb, line 32
    def initialize_attributes(attributes)
      attributes.each_pair do |att, value|
        next unless self.class.property?(att) || (self.class.respond_to?(:translations) && self.class.translations.include?(att.to_sym))
        self[att] = value
      end if attributes
    end

property_exists?(property) click to toggle source

    # File lib/hashie/extensions/ignore_undeclared.rb, line 39
    def property_exists?(property)
      self.class.property?(property)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.