[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Defining constants in global scope

Thomas Sondergaard

9/19/2003 6:46:00 PM

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


2 Answers

Peter C. Verhage

9/19/2003 8:29:00 PM

0

Thomas Sondergaard wrote:
> 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

nobu.nokada

9/24/2003 6:02:00 AM

0

Hi,

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

It works with latest CVS head.

--
Nobu Nakada