From: Josh Cheek Date: 2010-12-29T19:23:11+09:00 Subject: Re: convert String "1;2;3;4;5;" to Array --001485f92a887626ca049889f494 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Dec 28, 2010 at 5:19 PM, Thomas T. wrote: > Thanks to both. I'm reading up on these methods you've supplied at > http://www.ruby-doc.org/core/. It looks like the .map method is a > synonym for .collect. I'll read up on .inject next. > > > you mean something like this? > > > > "1;2;3;4;5;6;7;8;9;10".split(';').inject([]) { |a,i| a << i.to_i } > > => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > > > Yes. In fact, both of these work---liking ruby's flexibility here. > > #data = raw_data.split(/\;/).map { |raw| raw.to_f} > #data = raw_data.split(/\;/).inject([]) { |a,i| a << i.to_f } > > Go with map, this is its raison d'etre. --001485f92a887626ca049889f494--