Skip to content
Browse files

Add check for whether Module is already initialized

  • Loading branch information...
1 parent 733b56e commit 6f3a7abfa88925f907352974dbeff07e5bd34730 @dbussink dbussink committed
Showing with 9 additions and 1 deletion.
  1. +3 −1 kernel/common/class.rb
  2. +6 −0 kernel/common/module.rb
View
4 kernel/common/class.rb
@@ -5,7 +5,9 @@ class Class
##
# Specialized initialize_copy because Class needs additional protection
def initialize_copy(other)
- # Such a weird check.
+ # The code in super (Module#initialize_copy) will duplicate
+ # the method table. Therefore do this check here to see whether
+ # we've already initialized this class before continuing.
unless @method_table == other.method_table
raise TypeError, "already initialized class"
end
View
6 kernel/common/module.rb
@@ -582,6 +582,12 @@ def method_undefined(name)
private :method_undefined
def initialize_copy(other)
+ # If the method table is already different, we already
+ # initialized this module.
+ unless @method_table == other.method_table
+ raise TypeError, "already initialized module"
+ end
+
@method_table = other.method_table.dup
sc_s = Rubinius::Type.object_singleton_class self

0 comments on commit 6f3a7ab

Please sign in to comment.
Something went wrong with that request. Please try again.