On Mar 22, 2:56 pm, "Leslie Viljoen" <leslievilj... / gmail.com> wrote:
> On 3/22/07, Phrogz <g... / refinery.com> wrote:
> > On Mar 22, 9:15 am, "Leslie Viljoen" <leslievilj... / gmail.com> 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