From: "Peña, Botp" Date: 2004-02-12T11:39:32+09:00 Subject: Re: (noob) cast string to array? Koncept [mailto:user@unknown.invalid] humbly inquired: > result = { "foobar", "foobar", "foobar" } > > I want to basically remove the {}'s and replace them with [] > and cast result as an array so that I can have some fun within Ruby. > I think you do not need "[]" replacement since you just _need_ an "array". Remember, it just "looks like" ;-) c:\family\ruby>ruby -w a1.rb u is of class Array 0 'this' 1 'is a' 2 'test of wits' c:\family\ruby>cat a1.rb s = "{'this','is a','test of wits'}" # just a string t = s.gsub(/[\{}]/,'') # no more {} u = t.split(',').to_a # convert to array puts "u is of class #{u.class}" u.each_index {|i| puts "#{i} #{u[i]}"} I used each_index just in case you'll doubt if it's really an array. note, no eval there :-) > Koncept << kind regards -botp