Created
June 12, 2012 19:08
-
-
Save avdi/2919483 to your computer and use it in GitHub Desktop.
Class reloading breaks type-checking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
end | |
Foo.object_id # => 34581480 | |
f = Foo.new # => #<Foo:0x000000041f53c0> | |
f.class.object_id # => 34581480 | |
# This just prevents the "const redefined" warning | |
Object.send(:remove_const, :Foo) | |
# "Reload" class Foo | |
class Foo | |
end | |
Foo.object_id # => 34580180 | |
f.class.object_id # => 34581480 | |
f.is_a?(Foo) # => false | |
f.class == Foo # => false | |
f.class.name == "Foo" # => true |
Author
avdi
commented
Jun 14, 2012
via email
The conversation this was part of was discussing Rails autoloading in
development mode. It's not clear to newbs (until it's explained in an
example like this) that the autoloading mechanism works this way.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment