From: dblack@... Date: 2006-11-18T02:23:10+09:00 Subject: Re: Referncing values of local variables Hi -- On Sat, 18 Nov 2006, Thomas Luedeke wrote: > 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 That's not a constant; it's a local variable. It sounds like you might be running into scoping issues. > 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. I suspect you're doing something like: a = 3 def my_method temp_array = Array.new(a) end where a has gone out of scope by the time you use it. You can use a constant: A = 3 though that would normally be considered overkill, and bad design, unless it's really a constant that needs to be defined outside of any method, rather than a local variable or method argument. David -- David A. Black | dblack@rubypal.com Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org