[#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:6665] Re: printing/accessing arrays and hashes

From: Dave Thomas <Dave@...>
Date: 2000-11-30 05:41:14 UTC
List: ruby-talk #6665
raja@cs.indiana.edu (Raja S.) writes:

> Interesting that Ruby does a #to_s on the elements of the array
> first.

Actually, what happens is that when you concatenate something to an
existing string, if that something isn't already a string, its to_str
method is called.

   "a" + 1
   -:1:in `+': failed to convert Fixnum into String (TypeError)
	  from -:1

   class Fixnum
      def to_str
        "Number: " + to_s
      end
   end

   "a" + 1     #=> "aNumber: 1"


> Too bad that such a crucial issue as exception raising for
> out-of-bounds indexing in an array (or hash) got left out.  As, Dave
> suggests, I'm curious to try overloading [], []= to see if/what
> breaks.

Before you do that, though, can I suggest an experiment?

Do nothing. Just try it as it is, and see what happens. See how often
you get bitten by this. Perhaps adjust your coding style slightly to
adapt to a new language.

After a while, see what you think. Perhaps you'll have some horror
stories that will convince Matz to add IndexError exceptions. Or
perhaps you'll conclude it isn't necessary, and that perhaps it wasn't
so much "left out" as "designed out" ;-)


Regards


Dave

In This Thread