[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6017] Re: Exception handling

From: matz@... (Yukihiro Matsumoto)
Date: 2000-11-02 17:46:25 UTC
List: ruby-talk #6017
Hi,

In message "[ruby-talk:6012] Exception handling"
    on 00/11/03, David Suarez de Lis <excalibor@demasiado.com> writes:

|from the User's Manual:
|http://www.math.sci.hokudai.ac.jp/~gotoken/ruby/ruby-uguide/uguide25.html
|
|ruby> begin
|ruby|   file = open("/tmp/some_file", "w")
|ruby|   # something to do
|ruby| ensure
|ruby|   file.close
|ruby| end
|
|Let's suppose /tmp/some_file does not exist: then I get, from the ensure part: 
|
|NameError: undefined method `close' for nil
|
|Obviously, as open has failed in opening the file, 'file' references 'nil'...
|
|How do we cope with this kind of things?

It should have been:

  file = open("/tmp/some_file", "w")
  begin
    # something to do
  ensure
    file.close
  end

or even:

  open("/tmp/some_file", "w") do |file|
    # something to do
  end

The user guide was written almost 5 years ago; and I was not an
experienced Ruby programmer then ;-)

|PS- The documentation is great, and the library reference is superb,
|but many manuals, etc, are lagging behind the code... most are for
|ruby 1.4... eg. I saw an 'include Singleton' somewhere to create a
|singleton class, where in 1.4 that was done with 'class <<
|single'. Is there any updated documents like the Reference Manual for
|1.4 updated? While I still love _The Pragmatic Programmer_ by Dave
|and Andy, even after some 100 readings, at the current Euro rate,
|getting the Ruby book is off the question by now... thn

It's been in my todo list for long time;  I wish I had two (or even
more) individual souls.  Maybe I should setup RWiki to build
up-to-date references.

							matz.

In This Thread

Prev Next