In fact I have a single table inheritence ( yes, I'm doing a Rails app ). According to the action the user selects , I want to create the
apropriated object.
My English is very bad but I'll be very happy if you could help me.
cedric.ch wrote:
> Hi,
>
> I would to know if it is possible to do something like that:
>
> def create_object(class_name)
> my_object = **class_name**.new
> end
>
> I tried with class.new(&class_name)
x = Object.const_get( class_name ).new
--
James Britt
"Inside every large system there's a small system trying to get out".
- Chet Hendrickson
Does that still work if there's a module mentioned in the string with '::' included? I seem to remember a discussion or maybe an eigenclass blog entry that mentioned the problem. But maybe I'm wrong.
-Mat
路路路
On Dec 26, 2006, at 6:52 PM, James Britt wrote:
cedric.ch wrote:
Hi,
I would to know if it is possible to do something like that:
def create_object(class_name)
my_object = **class_name**.new
end
I tried with class.new(&class_name)
Hi,
I would to know if it is possible to do something like that:
def create_object(class_name)
my_object = **class_name**.new
end
I tried with class.new(&class_name)
x = Object.const_get( class_name ).new
Does that still work if there's a module mentioned in the string with '::' included? I seem to remember a discussion or maybe an eigenclass blog entry that mentioned the problem. But maybe I'm wrong.
-Mat
Well, try it and see:
module Foo
class Bar
def baz
warn 'BAZ!'
end
end
end