Module: KeyDial::Coercion::Arrays::ClassMethods

Defined in:
lib/key_dial/coercion.rb

Instance Method Summary collapse

Instance Method Details

#from(obj) ⇒ Object

Allows you to do Array.from(obj) to create an Array from any object intelligently.



68
69
70
71
72
73
# File 'lib/key_dial/coercion.rb', line 68

def from(obj)
  return obj if obj.is_a?(Array)
  return obj.to_a if obj.is_a?(Hash)
  return obj.to_h.to_a if obj.is_a?(Struct)
  return [obj]
end