Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

reload! in script/console re-defines classes.

#2771

Try this -

Create a file named lib/a.rb that defines a class A.

#file - lib/a.rb
def A
end

open script/console and type following

Loading development environment (Rails 2.3.2)
>> a = A.new
=> #<A:0x7f0b22b91160>
>> a.class
=> A
>> a.is_a? A
=> true
>> reload!
Reloading...
=> true
>> a.class
=> A
>> a.is_a? A
=> false

As you can see that a is no more an instance of A. This causes an ArgumentError for methods that validate arguments for their class.

You can type following code to see that reload! re-defines classes.

>> A.object_id
=> 70177791147340
>> reload!
Reloading...
=> true
>> A.object_id
=> 70177790965760

Using Rails 2.3.2 on Ubuntu 9.04

-thanks

Reported by Vikrant Chaudhary · June 6th, 2009 @ 06:43 AM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. thedarkone
    thedarkone

    This is an intended behavoir. reload! undefines all your constants, so they can be auto-required by ActiveSupport next time you use them.

    June 6th, 2009 @ 11:34 AM

  2. Vikrant Chaudhary
    Vikrant Chaudhary

    What advantage does reload! really have over typing exit and script/console again?

    June 6th, 2009 @ 12:47 PM

  3. thedarkone
    thedarkone

    You get to keep your current IRB session and it is about 1000-times faster. You can also give rails-dev-boost a try (it modifies ActiveSupport to only remove constants defined in the .rb files that have actually changed, so not everything gets nuked away).

    June 6th, 2009 @ 01:12 PM

  4. CancelProfileIsBroken
    CancelProfileIsBroken
    • State changed from new to invalid

    By design.

    June 6th, 2009 @ 01:25 PM