Module: KeyDial::Coercion::Hashes::ClassMethods

Defined in:
lib/key_dial/coercion.rb

Instance Method Summary collapse

Instance Method Details

#from(obj) ⇒ Object

Allows you to do Hash.from(obj) to create a Hash from any object intelligently.



21
22
23
24
25
26
# File 'lib/key_dial/coercion.rb', line 21

def from(obj)
  return obj if obj.is_a?(Hash)
  return obj.to_hash if obj.is_a?(Array)
  return obj.to_h if obj.is_a?(Struct)
  return {0 => obj}
end