Dynamically deleting a rails model -


i'm trying dynamically create , delete rails models. creation works not deletion.

i've tried deleting constant still present rails subclass:

object.send(:remove_const, :modeltobedeleted)  # check it's gone object object.constants.include? :modeltobedeleted # => false  # still in rails: activerecord::base.subclasses # returns  [modeltobedeleted(....)] 

i've tried using callback in finisher, when reloading in development:

activesupport::descendantstracker.clear activesupport::dependencies.clear 

but has no effect.

can me on how this? nick

classes garbage collected same way regular objects - when there's no references them.

most common references constants , instances, there may regular references. make sure references class gone

class cls; end c = class.new(cls) cls.subclasses # => [#<class:0x007fd64772dc68>] obj = c.new c = nil gc.start cls.subclasses # => [#<class:0x007fd64772dc68>] obj = nil gc.start cls.subclasses # => [] 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -