Module: MapWithIndifferentAccess::Values

Defined in:
lib/map_with_indifferent_access/values.rb

Class Method Summary collapse

Class Method Details

.externalize(obj) ⇒ Map, ... Also known as: >>

Converts obj to a Map or List if possible, otherwise returns obj.

Returns:



10
11
12
13
14
15
16
# File 'lib/map_with_indifferent_access/values.rb', line 10

def externalize(obj)
  (
    Map.try_convert( obj ) ||
    List.try_convert( obj ) ||
    obj
  )
end

.internalize(obj) ⇒ Hash, ... Also known as: <<

Converts obj, which might be a Map or List to a Hash or Array if possible. Returns obj if no conversion is possible.

Returns:

  • (Hash, Array, Object)


25
26
27
28
29
30
31
# File 'lib/map_with_indifferent_access/values.rb', line 25

def internalize(obj)
  (
    Map.try_deconstruct( obj ) ||
    List.try_deconstruct( obj ) ||
    obj
  )
end