开发者

How can I get a instance of a Class from a String in ruby? [duplicate]

开发者 https://www.devze.com 2023-03-29 08:29 出处:网络
This question already has answers here: 开发者_Python百科Closed 11 years ago. Possible Duplicate: How to convert a string to a constant in Ruby?
This question already has answers here: 开发者_Python百科 Closed 11 years ago.

Possible Duplicate:

How to convert a string to a constant in Ruby?

I am wondering whether there is a way for me to convert a string to a class in ruby. What i mean by this is that, given a String like

'Fixnum'

i want a way to get the class

Fixnum

back

can someone give me an idea on how to do this?


"FixNum".classify.contantize should do it

0

精彩评论

暂无评论...
验证码 换一张
取 消