Module: TTY::Conversion
Overview
A mixin to allow instances conversion to different types
Instance Method Summary collapse
-
#convert_to_array(object, copy = false) ⇒ Array
private
Converts the object into an Array.
Instance Method Details
#convert_to_array(object, copy = false) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the object into an Array. If copy is set to true a copy of object will be made.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tty/support/conversion.rb', line 17 def convert_to_array(object, copy=false) case object when Array copy ? object.dup : object when Hash Array(object) else begin converted = object.to_ary rescue Exception => e raise TTY::TypeError, "Cannot convert #{object.class} into an Array (#{e.})" end converted end end |