[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Absolute class name?

Mark J. Reed

10/2/2003 3:05:00 AM

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
12 Answers

nobu.nokada

10/2/2003 3:56:00 AM

0

Hi,

At Thu, 2 Oct 2003 12:45:03 +0900,
Mark J. Reed wrote:
> 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

--
Nobu Nakada

Mark J. Reed

10/2/2003 1:53:00 PM

0

MJR = me
NN = Nobu Nokada

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

NN> 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>

NN> If you use 1.6 still,

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

That works. Thanks!

-Mark

ts

10/2/2003 2:12:00 PM

0

>>>>> "M" == Mark J Reed <markjreed@mail.com> writes:

M> I beg to differ; I'm running 1.8.0 final (not preview) release,
M> 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

Mark J. Reed

10/2/2003 2:20:00 PM

0

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?

-Mark

Mark J. Reed

10/2/2003 2:52:00 PM

0

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?

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

-Mark

Mark J. Reed

10/2/2003 3:02:00 PM

0

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.

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

Mark J. Reed

10/2/2003 9:59:00 PM

0

NN = Nobu Nokada

NN> class X
NN> ::Object.class_eval do
NN> class Foo
NN> end
NN> end
NN> 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

nobu.nokada

10/2/2003 11:02:00 PM

0

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

nobu.nokada

10/2/2003 11:05:00 PM

0

Hi,

At Fri, 3 Oct 2003 00:06:47 +0900,
Mark J. Reed wrote:
> 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
from :0

--
Nobu Nakada

matz

10/2/2003 11:07:00 PM

0

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.