Subclassing Errno::XXX

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:inexception’
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:inexception’
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?

Hello,

In message “subclassing Errno::XXX”

···

on Dec.08,2003 14:47:38, vjoel@PATH.Berkeley.EDU wrote:

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,

U.Nakamura usa@osb.att.ne.jp

Hi,

···

In message “subclassing Errno::XXX” on 03/12/08, Joel VanderWerf vjoel@PATH.Berkeley.EDU writes:

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.

Hi,

···

At Mon, 8 Dec 2003 15:20:18 +0900, Yukihiro Matsumoto wrote:

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.


Nobu Nakada

Hi,

···

In message “Re: subclassing Errno::XXX” on 03/12/08, nobu.nokada@softhome.net nobu.nokada@softhome.net writes:

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.

Hi,

···

At Mon, 8 Dec 2003 17:47:57 +0900, Yukihiro Matsumoto wrote:

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));


Nobu Nakada

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

···

On Dec 8, 2003, at 2:47, Yukihiro Matsumoto wrote:

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?

Dave Thomas wrote:

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.

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

Hal

···

On Dec 8, 2003, at 2:47, Yukihiro Matsumoto wrote: