From: "Tom V." Date: 2007-05-07T18:06:22+09:00 Subject: Re: dynamically named variables or Constants Hi Logan, thanks for the hint. However that did not get me too far. So now I use simple instance variables and the session storage utility. But I always get a strange error that let me to the idea of using constants in the first place... Although this is a rails project using a plugin, the error I get is from using std ruby libraries. so maybe you can enlighten me... Please have a quick look: Constructor for creating a new "live_tree": class MyController # ... live_tree :fstree, :find_item_proc => Proc.new { |x| FileSystemItem.new(x, @user_path) } # ... end class FileSystemItem def initialize(path, root) @path = path log << "root = #{root} - class = #{root.class}\n" # output: # root = /user/path/ - class = String @root = File.expand_path(root) # ERROR: # TypeError (can't convert nil into String): # .//app/models/file_system_item.rb:17:in `expand_path' # .//app/models/file_system_item.rb:17:in `initialize' # .//app/controllers/my_controller.rb:452:in `new' end end "root" contains the user path and is of type String. However, when calling File.expand_path, I get the NameError. When using a constant or a global variable this error does not occur... Any ideas? Thanks for your time, Tom. On Mon, 7 May 2007 03:53:12 +0900 "Logan Capaldo" wrote: > > @new_constant = self::class::const_set(@constant_name, > > @constant_value) > > logger.info("#{@new_constant}") > > # output: /path/to/nirvana > > > > evaluate_constant = self::class::const_defined?(@new_constant) > > should be self::class:const_defined?(@constant_name) of course. > @new_constant is gonna hold the value of the constant, not the name.