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.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/key_dial/coercion.rb', line 82

def from(obj)
	case obj
	when Array
		return obj
	when Hash
		# Array from Hash
		return obj.to_a
	when Struct
		# Array from Struct
		return obj.to_h.to_a
	else
		return [obj]
	end
end