From: Logan Capaldo Date: 2007-05-07T20:26:10+09:00 Subject: Re: dynamically named variables or Constants ------=_Part_67372_7315427.1178537167854 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 5/7/07, Tom V. wrote: > > 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? That seems really weird. Maybe ruby is not being as clear with reporting the error as it could be. At this point I'd try using a debugger to get to the bottom of it. Thanks for your time, > Tom. > > > ------=_Part_67372_7315427.1178537167854--