From: Logan Capaldo Date: 2006-06-04T10:13:59+09:00 Subject: Re: private method `split' ? On Jun 3, 2006, at 9:07 PM, Sy Ali wrote: > Somehow, when trying to split an element in an array, split is no > longer working. > > I get this error: > > private method `split' called for # (NoMethodError) > > I can't show the code which generates the array, but I can reproduce > the error with something simple like this: > > puts ["a\nb", "c"].split("\n") > > However, imagine if you would that code like this could generate the > same private method error. > > array = ["a\nb", "c"] > puts array[0].split("\n") > > (where 'array[0]' is an element in a slightly complex array) > > > Why can't I use split with an element in my array? What's going on > here? > > I can do { puts array[0].inspect } and everything is normal.. > > > My goal is to convert an array which has strings of varying sizes (one > or more lines) into an array where each element has just one line of > text. Maybe there's a better way to do this and I can avoid this > wierdness? > array = [ "one line\n", "two line\nred line\n", "blue line" ] array.map { |elem| elem.to_a }.flatten #=> ["one line\n", "two line\n", "red line\n", "blue line"]