From: Francisco Martinez on
Hi, I have a problem, I have to write a method using an array but I'm
not able to combine the two things.
I have a txt file which contains words and puntuaction symbols separated
whit spaces.
I have to write a method which receives the txt file as a first entry
argument and returns an array of tokens. I have to call the methos and
print IN THE SCREEN all the tokens contained in the array the array in
this way:

token 1= the
token 2= house
token 3= is
token 4= big
token 5= .
--
Posted via http://www.ruby-forum.com/.

From: Jesús Gabriel y Galán on
On Wed, Aug 4, 2010 at 10:14 AM, Francisco Martinez
<calabazag(a)hotmail.es> wrote:
> Hi, I have a problem, I have to write a method using an array but I'm
> not able to combine the two things.
> I have a txt file which contains words and puntuaction symbols separated
> whit spaces.
> I have to write a method which receives the txt file as a first entry
> argument and returns an array of tokens. I have to call the methos and
> print IN THE SCREEN all the tokens contained in the array the array in
> this way:
>
> token 1= the
> token 2= house
> token 3= is
> token 4= big
> token 5= .

Take a look at the File#read and File#readline methods, and to
separate in tokens: String#split or String#scan.

Jesus.

From: Josh Cheek on
[Note: parts of this message were removed to make it a legal post.]

On Wed, Aug 4, 2010 at 3:14 AM, Francisco Martinez <calabazag(a)hotmail.es>wrote:

> Hi, I have a problem, I have to write a method using an array but I'm
> not able to combine the two things.
> I have a txt file which contains words and puntuaction symbols separated
> whit spaces.
> I have to write a method which receives the txt file as a first entry
> argument and returns an array of tokens. I have to call the methos and
> print IN THE SCREEN all the tokens contained in the array the array in
> this way:
>
> token 1= the
> token 2= house
> token 3= is
> token 4= big
> token 5= .
> --
> Posted via http://www.ruby-forum.com/.
>
>
StringScanner (in the stdlib) is intended for tasks like this. They show an
example at the start.
http://ruby-doc.org/stdlib/libdoc/strscan/rdoc/classes/StringScanner.html

From: Jesús Gabriel y Galán on
On Wed, Aug 4, 2010 at 11:01 AM, Josh Cheek <josh.cheek(a)gmail.com> wrote:
> On Wed, Aug 4, 2010 at 3:14 AM, Francisco Martinez <calabazag(a)hotmail.es>wrote:
>
>> Hi, I have a problem, I have to write a method using an array but I'm
>> not able to combine the two things.
>> I have a txt file which contains words and puntuaction symbols separated
>> whit spaces.
>> I have to write a method which receives the txt file as a first entry
>> argument and returns an array of tokens. I have to call the methos and
>> print IN THE SCREEN all the tokens contained in the array the array in
>> this way:
>>
>> token 1= the
>> token 2= house
>> token 3= is
>> token 4= big
>> token 5= .
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>>
> StringScanner (in the stdlib) is intended for tasks like this. They show an
> example at the start.
> http://ruby-doc.org/stdlib/libdoc/strscan/rdoc/classes/StringScanner.html

Thanks ! I had forgotten about StringScanner :-)

Jesus.