Class reference from parsing a string?


#1

Say I have a model class called Game. I also have a string call ‘game’.
How can I do some parsing magic on the string to have a reference to
the model Game. So I can perform class methods. (Game.find(1))

thanks


#2

On Dec 22, 2006, at 12:45 PM, warhero wrote:

Say I have a model class called Game. I also have a string call
‘game’.
How can I do some parsing magic on the string to have a reference to
the model Game. So I can perform class methods. (Game.find(1))

thanks

‘game’.camelize.constantize.find 1

– Ezra Z.
– Lead Rails Evangelist
– removed_email_address@domain.invalid
– Engine Y., Serious Rails Hosting
– (866) 518-YARD (9273)


#3

Vary dangerous, you need to be sure what is inside this string.
it’s like the notorious Eval.