[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Referncing values of local variables

Thomas Luedeke

11/17/2006 5:17:00 PM

I apologize in advance, because I know this gets asked again and again
(and again.....) by newbies, but my searches don't show a clear answer,
and none of my attempts work.

This should be simple. I want to define a constant,

a = 3

then reference the value of a in arguments like,

temp_array = Array.new(a)


such that the temp_array is assigned a size of 3.


This always seems to result in complaints about undefined local variable
or methods. Eval doesn't seem to make it work.

What I am doing wrong??

--
Posted via http://www.ruby-....

3 Answers

Stefano Crocco

11/17/2006 5:21:00 PM

0

> This should be simple. I want to define a constant,
>
> a = 3
>

In ruby, constant names begin with a capital letter (it is common
practice to use fully uppercase names) :

MY_CONSTANT=3

or

My_constant=3

Variable names starting with a lowercase letter define local variables.

--
Posted via http://www.ruby-....

dblack

11/17/2006 5:23:00 PM

0

Thomas Luedeke

11/17/2006 5:25:00 PM

0

Stefano Crocco wrote:
>> This should be simple. I want to define a constant,
>>
>> a = 3
>>
>
> In ruby, constant names begin with a capital letter (it is common
> practice to use fully uppercase names) :
>
> MY_CONSTANT=3
>
> or
>
> My_constant=3
>
> Variable names starting with a lowercase letter define local variables.

Umm, uh (crawls under desk in embarassment...). Thanks. :}

--
Posted via http://www.ruby-....