From: Nanyang Zhan Date: 2007-05-07T16:22:45+09:00 Subject: Re: passing by value of object of a model arjun ghosh wrote: > Hi, > can anyone tell me - is it possible to pass a string name equivalent of > a > model name(example:- have a model called food_dept and i am passing the > string "food_dept" to a method) and then covert(or cast) it to its > original > model equivalent so that i can use its object in the called method. and > why > i am i trying to this manner is because i want to avoid passing an > object > which will make it very heavy. i think there should be some better > elegant > manner of doing this. can any one help me with this? > ciao > -AG I know how to do it for RoR. If food_dept is a model(class) name,shouldn't it be FoodDept? if so, you can use this: "food_dept".camelize.constantize if you mean it's a method, use this: send("food_dept") >> class Foo >> def bar >> "test" >> end >> end => nil >> a="foo" => "foo" >> b="bar" => "bar" >> c = a.camelize.constantize.new => # >> c.send(b) => "test" but sadly, it seems this wouldn't work for ruby. -- Posted via http://www.ruby-forum.com/.