Module: Hashie::Extensions::Coercion

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

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Constant Summary collapse

CORE_TYPES =
{
  Integer    => :to_i,
  Float      => :to_f,
  Complex    => :to_c,
  Rational   => :to_r,
  String     => :to_s,
  Symbol     => :to_sym
}.freeze
ABSTRACT_CORE_TYPES =
if RubyVersion.new(RUBY_VERSION) >= RubyVersion.new('2.4.0')
  { Numeric => [Integer, Float, Complex, Rational] }
else
  {
    Integer => [Fixnum, Bignum],
    Numeric => [Fixnum, Bignum, Float, Complex, Rational]
  }
end

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/hashie/extensions/coercion.rb', line 29

def self.included(base)
  base.send :include, InstanceMethods
  base.extend ClassMethods
  unless base.method_defined?(:set_value_without_coercion)
    base.send :alias_method, :set_value_without_coercion, :[]=
  end
  base.send :alias_method, :[]=, :set_value_with_coercion
end