[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Converting a string to a class

Anthony DeRobertis

2/23/2006 3:10:00 PM

2 Answers

Michael Trier

2/23/2006 3:37:00 PM

0

Just learning, but what's wrong with eval? I do something like the
following in order to convert from a string to an object of the type
specified by the string:

a = "MyClass"
my_class = eval(a)
my_class.to_s

Michael


James Gray

2/23/2006 3:43:00 PM

0

On Feb 23, 2006, at 9:37 AM, Michael Trier wrote:

> Just learning, but what's wrong with eval? I do something like the
> following in order to convert from a string to an object of the type
> specified by the string:
>
> a = "MyClass"
> my_class = eval(a)
> my_class.to_s

eval() is a very powerful tool that we probably shouldn't use unless
we absolutely need too. What if the String contains typos or
malicious code? Also, it should be slower to compile and run some
code that to just do a constant lookup. Probably better to use the
tools intended for the operation is all.

James Edward Gray II