From: Mike Stok Date: 2006-06-04T11:53:16+09:00 Subject: Re: private method `split' ? On 3-Jun-06, at 10:25 PM, Sy Ali wrote: > On 6/3/06, Logan Capaldo wrote: >> 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"] > > Curious. That's not working as I'd expect. My misbehaving array > element still has \n in the middle of it. Is the misbehaving array element really a string, and what exactly are you doing in your code. In your earlier post you said: > 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.. but inspect turns things into strings. for example I can imagine code like this: ratdog:~ mike$ irb irb(main):001:0> class Foo irb(main):002:1> def initialize(s) ; @s = s ; end irb(main):003:1> def inspect ; @s ; end irb(main):004:1> end => nil irb(main):005:0> array = [Foo.new("one\ntwo\n")] => [one two ] irb(main):006:0> array[0].inspect => "one\ntwo\n" irb(main):007:0> array[0].split("\n") NoMethodError: private method `split' called for one two :Foo from (irb):7 from :0 Without more concrete information it is hard to guess at what is really going on! Mike -- Mike Stok http://www.stok.ca/~mike/ The "`Stok' disclaimers" apply.