IO#gets(sep_string) usage

Hello all. I’m trying to use the gets function, only I want to read
in a file and make separators any sort of punctuation(",", “:”, “\n”,
etc.).

My problem is trying to understand how the sep_string=$/ option is
supposed to work:

ios.gets(sep_string=$/)

How can I specify what sep_string is so that when I do something for a
while loop on gets, I can get each word instead of a line of text, or
lines of text with various punctuation I don’t want?

A second note, I’m not sure what $/ is supposed to mean. Is that the
separator for newline(which i thought was \n)?

Thanks in advance.

On 9/16/07, ZyLo [email protected] wrote:

while loop on gets, I can get each word instead of a line of text, or
lines of text with various punctuation I don’t want?

A second note, I’m not sure what $/ is supposed to mean. Is that the
separator for newline(which i thought was \n)?

$/ is the ‘output separator’ global. It defaults to \n.
What that syntax is saying is that you can pass a separator string to
IO#gets, and it will use it. If you don’t pass it one, it will use
whatever $/ is set to.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs