From: Hemant Kumar Date: 2007-01-28T19:32:13+09:00 Subject: Re: string into array On Sun, 2007-01-28 at 19:15 +0900, Josselin wrote: > I have the following string > id = "(48.88689971942316, 2.3380279541015625)" > is there any method to transform directly into an array > [48.88689971942316, 2.3380279541015625] or should extract both parts > and create the array (what I did.. but not very DRY) > > tfyl > > joss > > Since, I dunno abt really DRY way of doing that, I would go with this: class String def to_farray self.split(',').map {|part| part.gsub(/[()]/,"").to_f} end end a = "(48.88689971942316, 2.3380279541015625)" a.to_farray #=> [48.88689971942316, 2.3380279541015625]