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], # rubocop:disable Lint/UnifiedInteger
    Numeric => [Fixnum, Bignum, Float, Complex, Rational] # rubocop:disable Lint/UnifiedInteger
  }
end

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/hashie/extensions/coercion.rb', line 24

def self.included(base)
  base.send :include, InstanceMethods
  base.extend ClassMethods # NOTE: we wanna make sure we first define set_value_with_coercion before extending

  base.send :alias_method, :set_value_without_coercion, :[]= unless base.method_defined?(:set_value_without_coercion)
  base.send :alias_method, :[]=, :set_value_with_coercion
end