From: Mark Sparshatt Date: 2004-06-14T06:10:16+09:00 Subject: Re: Use a string a object name Mark Sparshatt wrote: > Dirk Einecke wrote: > >> Mark Sparshatt wrote: >> >>> puts eval "p.#{s}" >> >> >> >> Okay. That works. >> >>> Though depending on what you're doing a better way might be to use >>> the send method >>> >>> puts p.send(s) >> >> >> >> Why is this a better way? >> > It's quicker since Ruby doesn't need to parse the expression string. > > Also, IMHO, it better expresses the fact that you're sending the > message contained in s to the object p. > I forgot to mention there are using security concerns with using eval. If s is taken from an external source then it's possible for someone to set it to "send('system', 'rm -rf /')" which would very quickly ruin your day. -- Mark Sparshatt