Defining constants in global scope

T

Thomas Sondergaard

irb(main):001:0> module AModule
irb(main):002:1> end
=> nil
irb(main):003:0> AModule::AConstant = 1
=> 1
irb(main):004:0> ::AnotherConstant = 0
SyntaxError: compile error
(irb):4: syntax error
::AnotherConstant = 0
^
from (irb):4
irb(main):005:0>

Why can't I define a constant like this?

Cheers,

Tom
 
P

Peter C. Verhage

Thomas said:
Why can't I define a constant like this?

My guess is, and I'm new to Ruby so I'm probably wrong, that you first
need to open the "global" Module or class for which you want to define
the constant for. In this case this would be the Kernel module.

So something like:

Kernel::MyConstant = 1

Regards,

Peter
 
N

nobu.nokada

Hi,

At Sat, 20 Sep 2003 03:59:35 +0900,
Thomas said:
irb(main):004:0> ::AnotherConstant = 0
SyntaxError: compile error
(irb):4: syntax error
::AnotherConstant = 0
^

It works with latest CVS head.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,010
Latest member
MerrillEic

Latest Threads

Top