From: Masaomi Hatakeyama Date: 2010-12-29T16:54:31+09:00 Subject: Re: convert String "1;2;3;4;5;" to Array How about this? eval("[" + "1;2;3".gsub(/;/,',') + "]") => [1,2,3] Masa 2010/12/29 Adam Prescott : > I would avoid the inject solution because it's cumbersome and isn't as easy > to understand; map is pretty much to-the-point and doesn't have this weird > empty-array accumulator. The inject solution is just reinventing the map > wheel. > > On Tue, Dec 28, 2010 at 6:43 PM, Ian M. Asaff wrote: > >> Yep. >> >> --sent from myu droid. typoos courtesy of droid's crappy keyboarsd >> On Dec 28, 2010 6:41 PM, "Thomas T." wrote: >> > Ian M. Asaff wrote in post #971169: >> >> 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] >> > >> > Ok, I've read the page on .inject, but do have a question on your >> > solution. I'm interested in the [] where I read an initial value may be >> > supplied in .inject([]). Is the [] initializing an empty array to which >> > the accumulator, a, will populate? >> > >> > -- >> > Posted via http://www.ruby-forum.com/. >> > >> >