The question already has an accepted answer, but it's worth noting what the cause of the original problem was:
This is the problem part:
split('\t')
Ruby has several forms for quoted string, which have differences, usually useful ones.
Quoting from Ruby Programming at wikibooks.org:
...double quotes are designed to
interpret escaped characters such as
new lines and tabs so that they appear
as actual new lines and tabs when the
string is rendered for the user.
Single quotes, however, display the
actual escape sequence, for example
displaying \n instead of a new line.
Read further in the linked article to see the use of %q
and %Q
strings. Or Google for "ruby string delimiters", or see this SO question.
So '\t'
is interpreted as "backslash+t", whereas "\t"
is a tab character.
String#split
will also take a Regexp
, which in this case might remove the ambiguity:
split(/\t/)