1

I have this string :

temp = "["minutes", "hours"]"

If I do this:

temp[1..-2].split(", ")

I get an array of 2 elements like this:

[0] = ""minutes""
[1] = ""hours""

How can I avoid to have double quotes?

Tim Cooper
  • 151,519
  • 37
  • 317
  • 271
code-gijoe
  • 6,609
  • 12
  • 62
  • 101

3 Answers3

3

Use the JSON parser :

JSON.parse(your_array)
Intrepidd
  • 18,310
  • 5
  • 54
  • 63
2

One more:

the_string.scan(/\"(\w+)\"/).flatten
 => ["minutes", "hours"]
forker
  • 2,569
  • 4
  • 21
  • 24
1

Just do:

temp.gsub("\"", "")[1..-2].split(", ")

Or, once you have the array with double quotes on each element:

temp.map{|e| e.squeeze("̣\"")}
Alfonso
  • 758
  • 5
  • 8