Class: TTY::Conversion::ArrayConverter
- Inherits:
-
Object
- Object
- TTY::Conversion::ArrayConverter
- Defined in:
- lib/tty/conversion/converter/array.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #convert(value, copy = false) ⇒ Object
-
#initialize(source = String) ⇒ ArrayConverter
constructor
A new instance of ArrayConverter.
Constructor Details
#initialize(source = String) ⇒ ArrayConverter
Returns a new instance of ArrayConverter.
11 12 13 14 |
# File 'lib/tty/conversion/converter/array.rb', line 11 def initialize(source = String) @source = source @target = Array end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
9 10 11 |
# File 'lib/tty/conversion/converter/array.rb', line 9 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
7 8 9 |
# File 'lib/tty/conversion/converter/array.rb', line 7 def target @target end |
Instance Method Details
#convert(value, copy = false) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tty/conversion/converter/array.rb', line 17 def convert(value, copy = false) case value when Array copy ? value.dup : value when Hash Array(value) else begin converted = value.to_ary rescue Exception => e raise TTY::TypeError, "Cannot convert #{value.class} into an Array (#{e.})" end converted end end |