Module: Hashie::Extensions::Coercion::InstanceMethods

### Home Classes Methods

### In Files

- lib/hashie/extensions/coercion.rb

### Methods

- #custom_writer
- #replace
- #set_value_with_coercion

### 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::Coercion::InstanceMethods

### Public Instance Methods

custom_writer(key, value, _convert = true) click to toggle source

    # File lib/hashie/extensions/coercion.rb, line 77
    def custom_writer(key, value, _convert = true)
      self[key] = value
    end

replace(other_hash) click to toggle source

    # File lib/hashie/extensions/coercion.rb, line 81
    def replace(other_hash)
      (keys - other_hash.keys).each { |key| delete(key) }
      other_hash.each { |key, value| self[key] = value }
      self
    end

set_value_with_coercion(key, value) click to toggle source

    # File lib/hashie/extensions/coercion.rb, line 29
    def set_value_with_coercion(key, value)
      into = self.class.key_coercion(key) || self.class.value_coercion(value)

      return set_value_without_coercion(key, value) if value.nil? || into.nil?

      begin
        return set_value_without_coercion(key, coerce_or_init(into).call(value)) unless into.is_a?(Enumerable)

        if into.class <= ::Hash
          key_coerce = coerce_or_init(into.flatten[0])
          value_coerce = coerce_or_init(into.flatten[-1])
          value = into.class[value.map { |k, v| [key_coerce.call(k), value_coerce.call(v)] }]
        else # Enumerable but not Hash: Array, Set
          value_coerce = coerce_or_init(into.first)
          value = into.class.new(value.map { |v| value_coerce.call(v) })
        end
      rescue NoMethodError, TypeError => e
        raise CoercionError, "Cannot coerce property #{key.inspect} from #{value.class} to #{into}: #{e.message}"
      end

      set_value_without_coercion(key, value)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.