From: Mark Sparshatt Date: 2004-06-14T04:51:46+09:00 Subject: Re: Use a string a object name Dirk Einecke wrote: > Hi. > > I've a little problem. How can I use a string use as an object name? > > That works well: > puts p.name # -> dirk > > But how can I use the string s as object name, I tried eval but I the > result is not good. Where is my mistake. Can anybody help me? > > s = 'name' > puts eval "p.s" > since you want to put the value of s into the string that get's evaled you need to enclose it in #{ } like this puts eval "p.#{s}" Though depending on what you're doing a better way might be to use the send method puts p.send(s) -- Mark Sparshatt