From: Phrogz Date: 2007-03-23T06:45:11+09:00 Subject: Re: Knocking Lines Out Of A Multiline String On Mar 22, 2:56 pm, "Leslie Viljoen" wrote: > On 3/22/07, Phrogz wrote: > > On Mar 22, 9:15 am, "Leslie Viljoen" wrote: > > > lines = [] > > > File.new("text.txt").read.each_line {|line| lines << line } > > > lines.delete_if {|line| line =~ /\/usr\/local\/lib/} [snip] > > What you wrote creates a new File object and opens it, but never > > closes it. I'm not really sure what badness can result from this, but > > I gather it's not a good idea. > > This does sound rather frightening! What *is* the effect of opening a > file and not closing it? > ;-) > > Also, doesn't the above say that IO.read closes the file afterwards? IO.read (the class method) does open/close the file, but IO#read (the instance method) does not. Manually managing an IO object, you need something like: f = File.new('foo.txt') f.read f.close