creating objects type only known at runtime

A

Andrew Libby

This weekend I was playing around with some ruby and wanted
to create objects whose types were only known at runtime.
The method I wound up using was

o = eval "#{class_name}.new"

Is this a preferred method. I come from (mostly) a perl
background, but also a Java background. To me this approach
seems inelegant.

Thanks for any input.

Andy
 
F

Farrel Lifson

This weekend I was playing around with some ruby and wanted
to create objects whose types were only known at runtime.
The method I wound up using was

o = eval "#{class_name}.new"

Is this a preferred method. I come from (mostly) a perl
background, but also a Java background. To me this approach
seems inelegant.

Thanks for any input.

Andy

--
Andrew Libby
Tangeis, LLC
Innovative IT Management Solutions
(e-mail address removed)

o = Object.const_get(class_name).new

Farrel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top