On May 30, 2006, at 4:52 PM, Dan Kirkwood wrote: > Is there a better way to get to a class when you have the class > name in > a string? > (This is rails-related, btw).. For instance, if I have a string > clname > = 'Train', and I want to access a class method Train#label. I > can do > this: > > clname = 'Train' > label = eval "#{clname}.label" > > Is there a better way? > > -- > Posted via http://www.ruby-forum.com/. > In rails you can use #constantize clname = 'Train' clname.constantize.label But you really should try to search before posting. This was asked a bunch of times in the last few weeks. Cheers- -Ezra