How would you convert a string to an array in Ruby?
What I want to do is convert a string like "[value1, value2, value3]" to an array [value1, value2, value3]. Keep in mind some of these values may be strings themselves.
I am trying to write it in a method called str_to_ary.
def str_to_ary
@to_convert = self
#however everything I try beyond this point fails
end
value1, value2, value3? As is the question looks a bit ambiguous. It can be easily interpreted that they can be local variables defined beforehand, in which case this will require some eval black magic.value1,value2andvalue3. Presumably those are local variables or methods (not literals). Is that what you intend?