Are we even getting close?

Now we're getting somewhere!
I was thinking that I'd need one for each condition, and that one rescue for the three conditions is the result of misched-up thinking. I've seen too many sloppy programs that did this sort of thing. But Ruby is different?
Enquiring minds need to know...

···

Why do you need 3 blocks 'begin ... rescue' ? One is suffisant : the error
message will give you the reason of the failure

This is not the same with php

> 3 $conn = mysql_connect('localhost','xxxxx','xxxxxxx');
> 4 if ($conn == FALSE) {

here you must test the result of mysql_connect

> 5 echo 'Connection failed: '.mysql_error($conn);
> 6 } else {
> 7 mysql_select_db('mysql', $conn);
> 8 $query = "select host, user, password from user";
> 9 $res = mysql_query($query, $conn);
> 10 if ($res == NULL) {

here you must test the result of mysql_query

Guy Decoux

How do I obtain a reference to a classes superclass within a class so
that I can call superclass methods arbitrarily from the subclass?

I am extending the array class, and I need to access certain methods in
the array class (other than the one that I am currently using in the
subclass–so that super won’t work) in order to get the functionality
that I am looking for.

···

David King Landrith
(w) 617.227.4469x213
(h) 617.696.7133

One useless man is a disgrace, two
are called a law firm, and three or more
become a congress – John Adams

public key available upon request

Now we’re getting somewhere!
I was thinking that I’d need one for each condition, and that one rescue for
the three conditions is the result of misched-up thinking. I’ve seen too
many sloppy programs that did this sort of thing. But Ruby is different?
Enquiring minds need to know…

···

----- Original Message -----
From: “Ted” ted@datacomm.com
Newsgroups: comp.lang.ruby
Sent: Thursday, January 02, 2003 7:43 AM
Subject: Re: Are we even getting close?


Well, it depends on what you are trying to do. If you are just printing the
error and then exiting, then a top-level rescue is perfect for you. If you
want to recover from your error, then you put the rescue where you want the
recovery to happen.

So if your MySQL connection fails, you could just exit the program
(top-level rescue clause), or you could try to open a different database
(rescue should be right after your connection attempt)… it’s all about
where you want program execution to continue after you rescue the error.
(Honestly, if you are just printing the error and exiting, why rescue it at
all? Ruby will do that much for you! Unless for some reason you really
want the error message to go to $stdout instead of $stderr…)

Just my two cents,

Chris

Hi.

You can use the built-in iterator of the query result:

res.each { |row|

}

and IMO you don’t need to catch exceptions as it is just iteration over a
data structure located in in the RAM.

Regards,

Dalibor Sramek

···

On Fri, Jan 03, 2003 at 12:43:33AM +0900, Ted wrote:

Now we’re getting somewhere!

Dalibor Sramek insula.cz | In the eyes of cats,
dalibor.sramek@insula.cz | all things belong to cats.

How do I obtain a reference to a classes superclass within a class so
that I can call superclass methods arbitrarily from the subclass?

alias ?

Guy Decoux

David Landrith dlandrith@mac.com writes:

How do I obtain a reference to a classes superclass within a class so
that I can call superclass methods arbitrarily from the subclass?

I am extending the array class, and I need to access certain methods
in the array class (other than the one that I am currently using in
the subclass–so that super won’t work) in order to get the
functionality that I am looking for.

ts decoux@moulon.inra.fr writes:

alias ?

Yes you must alias the original method to a different name before you
redefine it in the sublcass.

class Foo < Array
alias_method :super_concat, :concat
def concat(other)
do_whatever(other)
end
def do_whatever(other)
super_concat(other)
end
end

Thank you. I've received so many helpful replies -- each from a different
angle -- that this thing might just be comprehensible. And, I'll learn
"The Ruby Way".

···

On Fri, 3 Jan 2003, Dalibor Sramek wrote:

On Fri, Jan 03, 2003 at 12:43:33AM +0900, Ted wrote:
> Now we're getting somewhere!
Hi.

You can use the built-in iterator of the query result:

res.each { |row|
...
}

and IMO you don't need to catch exceptions as it is just iteration over a
data structure located in in the RAM.

Regards,

Dalibor Sramek

--
Dalibor Sramek insula.cz | In the eyes of cats,
                dalibor.sramek@insula.cz | all things belong to cats.