Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/to_array.rb
Instance Method Summary collapse
Instance Method Details
#to_array ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/to_array.rb', line 2 def to_array if self[0] != "[" || self[-1] != "]" raise ArgumentError.new("invalid value for `str_to_array': '#{self}'") end begin arr = self.chomp.gsub(/"|^\[|\]$/, '') arr = arr.split(/,[\s]*/) return arr rescue raise ArgumentError.new("invalid value for `str_to_array': '#{self}'") end end |