On Jan 18, 6:31 am, Sem Ptiri <[email protected]> wrote:
> # APP_TABLES contain a list of table names - would be better to
> dynamically read them after connecting
>
> APP_TABLES.each do |table_name|
>   class_name = table_name.camelize
>   klass = Class.new(App)
>   constant_name = "#{class_name}"
>
>   # even though klass is created with App as superclass (inheriting from
> ActiveRecord::Base, the set_table_name seems to be unavailable - what am
> I missing here?

what happens when you try?

>   klass.set_table_name ("#{class_name}") or puts "Class set table name
> failed"
>   klass.const_set(constant_name, klass) or puts "Class name constant set
> failed"
>   eval("#{table_name} = #{class_name}.new") or puts "Class instantiation
> failed"
> end
>
> How can I determine if the klass has actually been created?

I  don't think Class.new can actually fail

> How long will the dynamic classes exist in memory?

> For the duration of this rake task execution?
> Is there a way to list classes created at runtime?

I think that klass exists much like any variable - it may be garbage
collected if nothing references it (classes might be special though) .
You can step through objects of any class (including Class) via
objectspace, although you probably won't be able to distinguish
classes created like this from other classes.

Fred
>
> --
> Posted viahttp://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to