Hi Stefano,

it's not working for me.
MyClass.const_get always returns a NameError.
Trying:

MyClass.const_defined?(session[:constant_name])

always returns 'false'
(except for the method where constant_name was defined...).

My guess is that 'session' cannot store Constants created the way I do it.
However, storing other large and complex objects is not a problem.

'session' is the standard Rails hash-like collection
using key/values pairs to store information
during subsequent requests from the same browser.
'@session' is deprecated now.

Thanks for your input.
Tom.

My Ruby version is:
ruby 1.8.5 (2006-12-04 patchlevel 2) [i686-linux]


On Sun, 6 May 2007 22:05:42 +0900
Stefano Crocco <stefano.crocco / alice.it> wrote:
>
> I can't understand why you get an error. I modified your code just a bit (by 
> the way, what exactly is session?) to give the two methods some context and 
> put it in a script:
> 
> class MyClass
> 
>   def initialize
>     @user = 'tom'
>     @session = {}
>   end
> 
>   def xyz_method
>   
>       constant_name = "#{@user.upcase}_VAR"
>   
>       constant = MyClass.const_set(constant_name, "/path/to/nirvana")
>       
>       @session[:constant_name] = constant_name
>   
>   end
>   
>   def abc_method
>   
>       @constant = MyClass.const_get(@session[:constant_name])
>       puts @constant
>   
>   end
> end
> 
> c = MyClass.new
> c.xyz_method
> c.abc_method
> 
> This works. Since I don't know anything about rails and the live tree plugin, 
> I may have missed something related to them. You can try using 
> MyClass.constants in the abc_method to get a list of the constants defined 
> for MyClass; this could give you some hints about what's happening.
> 
> Stefano
> 
> 
>