Module: Hashie::Extensions::IgnoreUndeclared
- Defined in:
- lib/hashie/extensions/ignore_undeclared.rb
Overview
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.
Instance Method Summary collapse
Instance Method Details
#initialize_attributes(attributes) ⇒ Object
32 33 34 35 36 37 |
# 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) ⇒ Boolean
39 40 41 |
# File 'lib/hashie/extensions/ignore_undeclared.rb', line 39 def property_exists?(property) self.class.property?(property) end |