Absolute class name?

If I do
class Foo

then that automatically refers to Foo in the current namespace.
How can I force a reference to the top-level Foo no matter what
namespace I’m in? class ::Foo is a syntax error.

-Mark

Hi,

If I do
class Foo

then that automatically refers to Foo in the current namespace.
How can I force a reference to the top-level Foo no matter what
namespace I’m in? class ::Foo is a syntax error.

It works in 1.8.

If you use 1.6 still,

class X
::Object.class_eval do
class Foo
end
end
end

···

At Thu, 2 Oct 2003 12:45:03 +0900, Mark J. Reed wrote:


Nobu Nakada

MJR = me
NN = Nobu Nokada

How can I force a reference to the top-level Foo no matter what
namespace I’m in? class ::Foo is a syntax error.

It works in 1.8.

I beg to differ; I’m running 1.8.0 final (not preview) release,
unpatched, and I get a syntax error:

irb(main):001:0> RUBY_VERSION
=> "1.8.0"
irb(main):002:0> class ::Foo
SyntaxError: compile error
(irb):2: syntax error
class ::Foo
        ^
        from (irb):2
irb(main):003:0> 

If you use 1.6 still,

class X
::Object.class_eval do
class Foo
end
end
end

That works. Thanks!

-Mark

I beg to differ; I'm running 1.8.0 final (not preview) release,
unpatched, and I get a syntax error:

It was corrected a little after the release of 1.8.0

···

Thu Aug 14 00:21:14 2003 Yukihiro Matsumoto <matz@ruby-lang.org>

  * parse.y (yylex): should return tCOLON3 right after kCLASS.
    [ruby-talk:78918]

Guy Decoux

NN = Nobu Nokada

class X
::Object.class_eval do
class Foo
end
end
end

Actually, that doesn’t work, either:

irb(main):001:0> class X
irb(main):002:1> ::Object.class_eval do
irb(main):003:2* class Foo
irb(main):004:3> def self.foo; puts “foo!”; end
irb(main):005:3> end
irb(main):006:2> end
irb(main):007:1> end
=> nil
irb(main):008:0> Foo.foo
NameError: uninitialized constant Foo
from (irb):8
irb(main):009:0> X::Foo.foo
foo!
=> nil
irb(main):010:0>

-Mark

Ah! Thanks. So any idea when these little fixes going to add up to a
1.8.1 release?

-Mark

···

On Thu, Oct 02, 2003 at 11:11:59PM +0900, ts wrote:

It was corrected a little after the release of 1.8.0

Thu Aug 14 00:21:14 2003 Yukihiro Matsumoto matz@ruby-lang.org

  • parse.y (yylex): should return tCOLON3 right after kCLASS.
    [ruby-talk:78918]

Hi,

···

At Fri, 3 Oct 2003 07:08:08 +0900, Mark J. Reed wrote:

Actually, that doesn’t work, either:

It’s for 1.6, constant scope rule has changed in 1.8.


Nobu Nakada

Also, where can I get this patch? It’s not in the 2003-09-09 diffs
on ftp.ruby-lang.org.

-Mark

···

On Thu, Oct 02, 2003 at 02:20:07PM +0000, Mark J. Reed wrote:

On Thu, Oct 02, 2003 at 11:11:59PM +0900, ts wrote:

It was corrected a little after the release of 1.8.0

Thu Aug 14 00:21:14 2003 Yukihiro Matsumoto matz@ruby-lang.org

* parse.y (yylex): should return tCOLON3 right after kCLASS.
[ruby-talk:78918]

Ah! Thanks. So any idea when these little fixes going to add up to a
1.8.1 release?

Okay, it is apparently included in the diffs, but it doesn’t work:

irb(main):001:0> RUBY_RELEASE_DATE
=> "2003-09-09"
irb(main):002:0> class ::Foo
SyntaxError: compile error
(irb):2: parse error
        from (irb):2
irb(main):003:0>

-Mark

···

On Thu, Oct 02, 2003 at 02:51:38PM +0000, Mark J. Reed wrote:

* parse.y (yylex): should return tCOLON3 right after kCLASS.
[ruby-talk:78918]

where can I get this patch? It’s not in the 2003-09-09 diffs
on ftp.ruby-lang.org.

Hi,

Okay, it is apparently included in the diffs, but it doesn’t work:

irb(main):001:0> RUBY_RELEASE_DATE
=> “2003-09-09”
irb(main):002:0> class ::Foo
SyntaxError: compile error
(irb):2: parse error
from (irb):2
irb(main):003:0>

The parser in irb hasn’t been updated.

$ ruby -v -e ‘class ::Foo; p self; end’
ruby 1.8.0 (2003-10-02) [i686-linux]
Foo
$ irb
irb(main):001:0> class ::Foo; p self; end
Foo
=> nil
irb(main):002:0> class ::Foo
SyntaxError: compile error
(irb):2: syntax error
from (irb):2

···

At Fri, 3 Oct 2003 00:06:47 +0900, Mark J. Reed wrote:
from :0


Nobu Nakada

Hi,

···

In message “Re: Absolute class name?” on 03/10/03, “Mark J. Reed” markjreed@mail.com writes:

Okay, it is apparently included in the diffs, but it doesn’t work:

irb doesn’t support this syntax yet.

						matz.

Oh, so I see. Thanks!

But now I’m curious - why does irb have a different parser from regular ruby?
That seems likely to cause all sorts of such incompatibilities, since
you have to maintain similar code in two places . . .

-Mark

···

On Fri, Oct 03, 2003 at 08:06:47AM +0900, Yukihiro Matsumoto wrote:

irb doesn’t support this syntax yet.

Hi,

···

In message “Re: Absolute class name?” on 03/10/04, “Mark J. Reed” markjreed@mail.com writes:

But now I’m curious - why does irb have a different parser from regular ruby?
That seems likely to cause all sorts of such incompatibilities, since
you have to maintain similar code in two places . . .

Ah, historical reason, reserved to be solved in the future (Rite).

						matz.