subclassing Errno::XXX

  • Thread starter Joel VanderWerf
  • Start date
J

Joel VanderWerf

What changed from 1.7.3 to 1.8.0 and 1.8.1 that could have caused this?

[~] ruby-1.7.3 -v -e 'class MissingFileError < Errno::ENOENT; end;
raise MissingFileError, "foo"'
ruby 1.7.3 (2002-12-20) [i686-linux]
-e:1: foo (MissingFileError)

[~] ruby-1.8.0 -v -e 'class MissingFileError < Errno::ENOENT; end;
raise MissingFileError, "foo"'
ruby 1.8.0 (2003-08-04) [i686-linux]
-e:1:in `initialize': uninitialized constant MissingFileError::Errno
(NameError)
from -e:1:in `exception'
from -e:1:in `raise'
from -e:1

[~] ruby-1.8.1 -v -e 'class MissingFileError < Errno::ENOENT; end;
raise MissingFileError, "foo"'
ruby 1.8.1 (2003-10-31) [i686-linux]
-e:1:in `initialize': uninitialized constant MissingFileError::Errno
(NameError)
from -e:1:in `exception'
from -e:1:in `raise'
from -e:1

I've decided to no longer subclass in this way, for other reasons, but
I'm still curious. Is it a scope thing? Or just something about Errno?
 
U

U.Nakamura

Hello,

In message "subclassing Errno::XXX"
| I've decided to no longer subclass in this way, for other reasons, but
| I'm still curious. Is it a scope thing? Or just something about Errno?

p Errno::ENOENT::Errno # => 2

Errno::XXXX and their subclasses must have constant named Errno.


Regards,
 
Y

Yukihiro Matsumoto

Hi,

In message "subclassing Errno::XXX"

|What changed from 1.7.3 to 1.8.0 and 1.8.1 that could have caused this?

In 1.8, Errno::XXX classes are required to define Errno constant that
shows its errno.

matz.
 
N

nobu.nokada

Hi,

At Mon, 8 Dec 2003 15:20:18 +0900,
Yukihiro said:
|What changed from 1.7.3 to 1.8.0 and 1.8.1 that could have caused this?

In 1.8, Errno::XXX classes are required to define Errno constant that
shows its errno.

I'm getting to feel a subclass of SystemCallError may inherit
it, although agree that still a direct child must define it.
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: subclassing Errno::XXX"
|> In 1.8, Errno::XXX classes are required to define Errno constant that
|> shows its errno.
|
|I'm getting to feel a subclass of SystemCallError may inherit
|it, although agree that still a direct child must define it.

I'm not sure what you mean. Do you mean when MissingFileError
inherits from Errno::ENOENT, it should inherit Errno constat from
Errno::ENOENT as well?

matz.
 
N

nobu.nokada

Hi,

At Mon, 8 Dec 2003 17:47:57 +0900,
Yukihiro said:
|> In 1.8, Errno::XXX classes are required to define Errno constant that
|> shows its errno.
|
|I'm getting to feel a subclass of SystemCallError may inherit
|it, although agree that still a direct child must define it.

I'm not sure what you mean. Do you mean when MissingFileError
inherits from Errno::ENOENT, it should inherit Errno constat from
Errno::ENOENT as well?

I meant SystemCallError#initialize should use Errno in the
parent class.


Index: error.c
===================================================================
RCS file: /cvs/ruby/src/ruby/error.c,v
retrieving revision 1.83
diff -u -2 -p -r1.83 error.c
--- error.c 22 Nov 2003 03:59:17 -0000 1.83
+++ error.c 8 Dec 2003 09:18:36 -0000
@@ -594,5 +594,5 @@ syserr_initialize(argc, argv, self)
else {
rb_scan_args(argc, argv, "01", &mesg);
- error = rb_const_get_at(klass, rb_intern("Errno"));
+ error = rb_const_get(klass, rb_intern("Errno"));
}
if (!NIL_P(error)) err = strerror(NUM2LONG(error));
 
D

Dave Thomas

I'm not sure what you mean. Do you mean when MissingFileError
inherits from Errno::ENOENT, it should inherit Errno constat from
Errno::ENOENT as well?

I'm not addressing Nobu's point, but there is an argument to say that
there is no meaningful inheritance at all if you _change_ Errno: that
is, if you subclass an Errno::Xxx, the Errno constant in the subclass
must be identical to that in the parent (otherwise it isn't a true
subclass). After all, these classes are essentially wrappers for the
Errno value, and so for a subclass to maintain the "isa" relationship
it must wrap the same value too.

Cheers

Dave
 
H

Hal Fulton

Dave said:
I'm not addressing Nobu's point, but there is an argument to say that
there is no meaningful inheritance at all if you _change_ Errno: that
is, if you subclass an Errno::Xxx, the Errno constant in the subclass
must be identical to that in the parent (otherwise it isn't a true
subclass). After all, these classes are essentially wrappers for the
Errno value, and so for a subclass to maintain the "isa" relationship it
must wrap the same value too.

If that's the case, maybe it should be a reader class method wrapping
an anonymous constant?

Hal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,125
Messages
2,570,748
Members
47,302
Latest member
MitziWragg

Latest Threads

Top