Yukihiro Matsumoto [mailto:matz / ruby-lang.org] wrote:
//I feel it might be difficult.  Define the following:
//
//  "abc\n".split("\n").join("\n")

I thought we can cater that w a limit parameter,

irb(main):040:0>  "\nabc\ndef\n".split("\n",-1).join("\n")
=> "\nabc\ndef\n"

and that split by itself (w/o limit param) simplifies by trimming trailing
edges -which is good in some cases, imho.

My remainng concern is [] vs [""] thingy. Both behave similarly w split and
joins, yet I prefer the [""]. But that is just me.

irb(main):046:0> "a".split("b")
=> ["a"]
irb(main):047:0> "".split("b")
=> []  #<=== I was hoping for [""] here

No worry here, this just very small concern.

irb(main):065:0> [""].collect{|x| x+"!"}
=>["!"]
irb(main):066:0> [].collect{|x| x+"!"}
=>[]   #<== [] acts like blackhole

Thank you, sir Matz.

//
//							matz.

kind regards -botp