From: GOTO Kentaro Date: 2002-09-24T05:00:39+09:00 Subject: Re: Speed up suggestions At Tue, 24 Sep 2002 03:58:45 +0900, Kent Dahl wrote: > I am confused. Ruby '\n' is not equivalent with Ruby "\n", so a > difference would not be unexpected. (The size of the difference perhaps) As you said '\n' != "\n" and '\n' == "\\n" indeed. And also p Regexp.new("\n") == eval("/\n/") #=> true p Regexp.new("\\n") == eval("/\\n/") #=> true Try below if you are confused: p "/\n/" p "/\\n/" By the way, in 1.7.x, String#split behavior was changed about a month ago: % ruby17 -e 'p "a\nb".split("\\n")' -e:1: warning: string pattern instead of regexp; metacharacters no longer effective ["a\nb"] % ruby17 -e 'p "a\\nb".split("\\n")' -e:1: warning: string pattern instead of regexp; metacharacters no longer effective ["a", "b"] In current version 1.7.3, split(sep) does like as follows: def split(sep) case sep when String sep = if sep.size > 1 Regexp.new(Regexp.escape(sep)) else Regexp.new(sep) end when Regexp else raise TypeError, "wrong argument type #{sep.type} (expected Regexp)" end And do real split action with sep end -- Gotoken