This project is archived and is in readonly mode.

reload! in script/console re-defines classes.
Reported by Vikrant Chaudhary | June 6th, 2009 @ 06:43 AM | in 2.x
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
Comments and changes to this ticket
-
thedarkone June 6th, 2009 @ 11:34 AM
This is an intended behavoir.
reload!
undefines all your constants, so they can be auto-required byActiveSupport
next time you use them. -
Vikrant Chaudhary June 6th, 2009 @ 12:47 PM
What advantage does reload! really have over typing exit and script/console again?
-
thedarkone June 6th, 2009 @ 01:12 PM
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). -
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>