Rajan AgaskarRajan Agaskar
Standup 10/30/08
edit Posted by Rajan Agaskar on Thursday October 30, 2008 at 04:17PM

Interesting Things

  • Removing class definitions with Object.send(:remove_const, :Foo)

Sometimes it is necessary to reload or replace a stub/test class during testing (apparently rspec is particularly susceptible to this). This can be achieved using Object.send(:remove_const, :Foo) where Foo is the camel-cased name of the class. If your class is defined within a module, it may be necessary to use Module.send(:remove_const, :Foo)

Ask for help

  • foo.bar.reload versus foo.bar(true)

As a point of curiosity, does anybody know when has_many relationship reloading moved from (or to?) foo.bar(true) to foo.bar.reload? The reload syntax seems preferable for readability; will foo.bar(true) continue to work in the future?

Comments

  1. Pat Nakajima Pat Nakajima on October 31, 2008 at 02:01PM

    Calling #reload is just an instance method on ActiveRecord::Base to reload whatever object you call it on from the database. Since the bar in foo.bar is just an ActiveRecord, you can reload it.

    The foo.bar(true) syntax is an association proxy specific way of reloading your association.

    I think.