Include? only true once

blockFile = File.new("blocklist.txt", "a+")
print blockFile.read.include?("aa")

blocklist.txt looks like

···

--------------------------------------------
aa
ae
aj
au
ae
---------------------------------------------

Why does #include? return true on the first call only?

Thank you,
Matthew Margolis

Hi --

···

On Tue, 7 Sep 2004, Matthew Margolis wrote:

blockFile = File.new("blocklist.txt", "a+")
print blockFile.read.include?("aa")
print blockFile.read.include?("aa")

blocklist.txt looks like
--------------------------------------------
aa
ae
aj
au
ae
---------------------------------------------

Why does #include? return true on the first call only?

Because you've reached end-of-file :slight_smile:

David

--
David A. Black
dblack@wobblini.net

David A. Black wrote:

Hi --

blockFile = File.new("blocklist.txt", "a+")
print blockFile.read.include?("aa")

blocklist.txt looks like
--------------------------------------------
aa
ae
aj
au
ae
---------------------------------------------

Why does #include? return true on the first call only?
   
Because you've reached end-of-file :slight_smile:

David

blockFile = File.new("blocklist.txt", "a+")
print blockFile.read.include?("aa")
blockFile.lineno = 0
print blockFile.read.include?("aa")

Still gives true false instead of true true

-Matthew Margolis

···

On Tue, 7 Sep 2004, Matthew Margolis wrote:

Hi --

···

On Tue, 7 Sep 2004, Matthew Margolis wrote:

David A. Black wrote:

>Hi --
>
>On Tue, 7 Sep 2004, Matthew Margolis wrote:
>
>
>
>>blockFile = File.new("blocklist.txt", "a+")
>>print blockFile.read.include?("aa")
>>print blockFile.read.include?("aa")
>>
>>blocklist.txt looks like
>>--------------------------------------------
>>aa
>>ae
>>aj
>>au
>>ae
>>---------------------------------------------
>>
>>
>>Why does #include? return true on the first call only?
>>
>>
>
>Because you've reached end-of-file :slight_smile:
>
>
>David
>
>
>
blockFile = File.new("blocklist.txt", "a+")
print blockFile.read.include?("aa")
blockFile.lineno = 0
print blockFile.read.include?("aa")

Still gives true false instead of true true

I'm ignorant of #lineno= but it doesn't seem to affect EOF. (If you
add an EOF test it will come out true.) But you could use #pos to get
back to the beginning of the stream.

David

--
David A. Black
dblack@wobblini.net

David A. Black wrote:

Hi --

David A. Black wrote:

Hi --

blockFile = File.new("blocklist.txt", "a+")
print blockFile.read.include?("aa")

blocklist.txt looks like
--------------------------------------------
aa
ae
aj
au
ae
---------------------------------------------

Why does #include? return true on the first call only?
  

Because you've reached end-of-file :slight_smile:

David

blockFile = File.new("blocklist.txt", "a+")
print blockFile.read.include?("aa")
blockFile.lineno = 0
print blockFile.read.include?("aa")

Still gives true false instead of true true
   
I'm ignorant of #lineno= but it doesn't seem to affect EOF. (If you
add an EOF test it will come out true.) But you could use #pos to get
back to the beginning of the stream.

David

Excellent, thank you.

-Matthew Margolis

···

On Tue, 7 Sep 2004, Matthew Margolis wrote:

On Tue, 7 Sep 2004, Matthew Margolis wrote:

"Matthew Margolis" <mrmargolis@wisc.edu> schrieb im Newsbeitrag
news:413CEF14.2070102@wisc.edu...

David A. Black wrote:

>Hi --
>
>
>
>
>>David A. Black wrote:
>>
>>
>>
>>>Hi --
>>>
>>>
>>>
>>>
>>>
>>>
>>>>blockFile = File.new("blocklist.txt", "a+")
>>>>print blockFile.read.include?("aa")
>>>>print blockFile.read.include?("aa")
>>>>
>>>>blocklist.txt looks like
>>>>--------------------------------------------
>>>>aa
>>>>ae
>>>>aj
>>>>au
>>>>ae
>>>>---------------------------------------------
>>>>
>>>>
>>>>Why does #include? return true on the first call only?
>>>>
>>>>
>>>>
>>>>
>>>Because you've reached end-of-file :slight_smile:
>>>
>>>
>>>David
>>>
>>>
>>>
>>>
>>>
>>blockFile = File.new("blocklist.txt", "a+")
>> print blockFile.read.include?("aa")
>> blockFile.lineno = 0
>> print blockFile.read.include?("aa")
>>
>>Still gives true false instead of true true
>>
>>
>
>I'm ignorant of #lineno= but it doesn't seem to affect EOF. (If you
>add an EOF test it will come out true.) But you could use #pos to get
>back to the beginning of the stream.
>
>
>David
>
>
>
Excellent, thank you.

-Matthew Margolis

Why don't you just:

# complete:
content = File.read("blocklist.txt")
print content.include?("aa")
print content.include?("aa")

# line oriented:
content = File.readlines("blocklist.txt")
print content.include?("aa")
print content.include?("aa")

Much more efficient if the file fits into mem.

Kind regards

    robert

···

>On Tue, 7 Sep 2004, Matthew Margolis wrote:
>>>On Tue, 7 Sep 2004, Matthew Margolis wrote: