From c7ac644f830ecf7ee1131324afedf0cb67f5920b Mon Sep 17 00:00:00 2001 From: Evan Phoenix Date: Sat, 27 Mar 2010 12:23:35 -0700 Subject: [PATCH] Finish phasing out using #metaclass in the kernel. Fixes #189. --- kernel/bootstrap/kernel.rb | 2 +- kernel/common/compiled_method.rb | 2 +- kernel/common/eval.rb | 9 ++++++--- kernel/common/kernel.rb | 10 +++++----- kernel/common/module.rb | 6 +++--- kernel/common/native_method.rb | 11 +++++++---- kernel/delta/module.rb | 2 +- kernel/platform/library.rb | 2 +- 8 files changed, 25 insertions(+), 19 deletions(-) diff --git a/kernel/bootstrap/kernel.rb b/kernel/bootstrap/kernel.rb index 0ea90f7b94..a9ad2050fe 100644 --- a/kernel/bootstrap/kernel.rb +++ b/kernel/bootstrap/kernel.rb @@ -11,7 +11,7 @@ def eql?(other) # HACK dup of equal? end def extend(*mods) - metaclass.include(*mods) + Rubinius.object_metaclass(self).include(*mods) self end diff --git a/kernel/common/compiled_method.rb b/kernel/common/compiled_method.rb index 3b386428fe..86e6f4062c 100644 --- a/kernel/common/compiled_method.rb +++ b/kernel/common/compiled_method.rb @@ -232,7 +232,7 @@ def as_script(script=nil) ss.script = script @scope = ss - mc = MAIN.metaclass + mc = Rubinius.object_metaclass(MAIN) mc.method_table.store :__script__, self, :public compile VM.reset_method_cache :__script__ diff --git a/kernel/common/eval.rb b/kernel/common/eval.rb index 6d238173fe..967bdcce81 100644 --- a/kernel/common/eval.rb +++ b/kernel/common/eval.rb @@ -136,13 +136,15 @@ def eval(string, binding=nil, filename=nil, lineno=1) # k.instance_eval { @secret } #=> 99 def instance_eval(string=nil, filename="(eval)", line=1, &prc) + mc = Rubinius.object_metaclass(self) + if prc if string raise ArgumentError, 'cannot pass both a block and a string to evaluate' end # Return a copy of the BlockEnvironment with the receiver set to self env = prc.block - static_scope = env.method.scope.using_current_as(__metaclass__) + static_scope = env.method.scope.using_current_as(mc) return env.call_under(self, static_scope, self) elsif string string = StringValue(string) @@ -153,7 +155,7 @@ def instance_eval(string=nil, filename="(eval)", line=1, &prc) Rubinius::StaticScope.of_sender) cm = Rubinius::Compiler.compile_eval string, binding.variables, filename, line - cm.scope = binding.static_scope.using_current_as(metaclass) + cm.scope = binding.static_scope.using_current_as(mc) cm.name = :__instance_eval__ cm.compile @@ -192,7 +194,8 @@ def instance_eval(string=nil, filename="(eval)", line=1, &prc) def instance_exec(*args, &prc) raise ArgumentError, "Missing block" unless block_given? env = prc.block - static_scope = env.method.scope.using_current_as(__metaclass__) + mc = Rubinius.object_metaclass(self) + static_scope = env.method.scope.using_current_as(mc) return env.call_under(self, static_scope, *args) end end diff --git a/kernel/common/kernel.rb b/kernel/common/kernel.rb index 708f1021d6..2d1a8e7eb0 100644 --- a/kernel/common/kernel.rb +++ b/kernel/common/kernel.rb @@ -552,12 +552,12 @@ def nil? def methods(all=true) methods = singleton_methods(all) - methods |= self.metaclass.instance_methods(true) if all + methods |= Rubinius.object_metaclass(self).instance_methods(true) if all return methods if kind_of?(ImmediateValue) undefs = [] - metaclass.method_table.filter_entries do |entry| + Rubinius.object_metaclass(self).method_table.filter_entries do |entry| undefs << entry.name.to_s if entry.visibility == :undef end @@ -569,7 +569,7 @@ def private_methods(all=true) end def private_singleton_methods - Rubinius.convert_to_names metaclass.method_table.private_names + Rubinius.convert_to_names Rubinius.object_metaclass(self).method_table.private_names end def protected_methods(all=true) @@ -577,7 +577,7 @@ def protected_methods(all=true) end def protected_singleton_methods - Rubinius.convert_to_names metaclass.method_table.protected_names + Rubinius.convert_to_names Rubinius.object_metaclass(self).method_table.protected_names end def public_methods(all=true) @@ -585,7 +585,7 @@ def public_methods(all=true) end def singleton_methods(all=true) - mt = metaclass.method_table + mt = Rubinius.object_metaclass(self).method_table methods = (all ? mt.names : mt.public_names + mt.protected_names) Rubinius.convert_to_names methods diff --git a/kernel/common/module.rb b/kernel/common/module.rb index 659abe1290..2f5da0bbca 100644 --- a/kernel/common/module.rb +++ b/kernel/common/module.rb @@ -161,7 +161,7 @@ def superclass_chain end def find_class_method_in_hierarchy(sym) - self.metaclass.find_method_in_hierarchy(sym) + Rubinius.object_metaclass(self).find_method_in_hierarchy(sym) end def remote_alias(new_name, mod, current_name) @@ -392,7 +392,7 @@ def set_visibility(meth, vis, where = nil) end def set_class_visibility(meth, vis) - metaclass.set_visibility meth, vis, "class " + Rubinius.object_metaclass(self).set_visibility meth, vis, "class " end def protected(*args) @@ -694,7 +694,7 @@ def normalize_const_name(name) def initialize_copy(other) @method_table = other.method_table.dup - metaclass.method_table = other.metaclass.method_table.dup + Rubinius.object_metaclass(self).method_table = Rubinius.object_metaclass(other).method_table.dup @constants = Rubinius::LookupTable.new diff --git a/kernel/common/native_method.rb b/kernel/common/native_method.rb index 59b8e2374b..7fef86df9c 100644 --- a/kernel/common/native_method.rb +++ b/kernel/common/native_method.rb @@ -18,12 +18,15 @@ class NativeMethod < Executable # def self.load_extension(library_path, extension_name) library = library_path.sub /#{Rubinius::LIBSUFFIX}$/, '' - symbol = "Init_#{extension_name}" + name = "Init_#{extension_name}" - entry_point = load_entry_point library, symbol + entry_point = load_entry_point library, name - Rubinius.metaclass.method_table.store symbol.to_sym, entry_point, :public - Rubinius.send symbol.to_sym + symbol = name.to_sym + + Rubinius.object_metaclass(self).method_table.store symbol, entry_point, :public + Rubinius::VM.reset_method_cache(symbol) + __send__ symbol true end diff --git a/kernel/delta/module.rb b/kernel/delta/module.rb index 9aa6da00d3..4a032f4dd7 100644 --- a/kernel/delta/module.rb +++ b/kernel/delta/module.rb @@ -51,7 +51,7 @@ def module_function(*args) Rubinius::VariableScope.of_sender.method_visibility = :module else - mc = self.metaclass + mc = Rubinius.object_metaclass(self) args.each do |meth| method_name = Type.coerce_to_symbol meth method = find_method_in_hierarchy(method_name) diff --git a/kernel/platform/library.rb b/kernel/platform/library.rb index 7439a0131b..014d402ef0 100644 --- a/kernel/platform/library.rb +++ b/kernel/platform/library.rb @@ -95,7 +95,7 @@ def attach_function(name, a3, a4, a5=nil) if func = create_backend(lib, cname, args, ret) # Make it available as a method callable directly.. - metaclass.method_table.store mname, func, :public + Rubinius.object_metaclass(self).method_table.store mname, func, :public # and expose it as a private method for people who # want to include this module.