IO#gets(sep_string) usage

Z

ZyLo

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.
 
W

Wilson Bilkovich

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)?

$/ 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top