Module Hashie::Extensions::Coercion::ClassMethods
In: lib/hashie/extensions/coercion.rb

Methods

Public Instance methods

Set up a coercion rule such that any time the specified key is set it will be coerced into the specified class. Coercion will occur by first attempting to call Class.coerce and then by calling Class.new with the value as an argument in either case.

@param [Object] key the key or array of keys you would like to be coerced. @param [Class] into the class into which you want the key(s) coerced.

@example Coerce a "user" subhash into a User object

  class Tweet < Hash
    include Hashie::Extensions::Coercion
    coerce_key :user, User
  end
coerce_keys(*attrs)

Alias for coerce_key

Set up a coercion rule such that any time a value of the specified type is set it will be coerced into the specified class.

@param [Class] from the type you would like coerced. @param [Class] into the class into which you would like the value coerced. @option options [Boolean] :strict (true) whether use exact source class only or include ancestors

@example Coerce all hashes into this special type of hash

  class SpecialHash < Hash
    include Hashie::Extensions::Coercion
    coerce_value Hash, SpecialHash

    def initialize(hash = {})
      super
      hash.each_pair do |k,v|
        self[k] = v
      end
    end
  end

Returns the specific key coercion for the specified key, if one exists.

Returns a hash of any existing key coercions.

Return all value coercions that have the :strict rule as false.

Return all value coercions that have the :strict rule as true.

Fetch the value coercion, if any, for the specified object.

[Validate]