D
DaZoner
I've defined a class I use that strips methods off of a class (specified by
a string representing the class name). I use it maybe 30 times during my
application run. However I'm concerned because it does an
ObjectSpace.each(Class) call to make sure the specified class exists before
trying to remove any methods. Will this call get slow as a few arrays
containing perhaps a million FixNums get defined by the application in
between calls? The array's data stays around as the calls to my class are
made. I've included the source of the class below. If anyone knows an
efficient way to determine if a class exists given its name in String form
I'd sure appreciate seeing it.
class MethodRemover
def initialize(className)
@className = className
@codeString = "class " + className +"\n" +
" public_instance_methods(false).each do | method |\n" +
" code = \"class #{className} remove_method
:\"\+method\+\" end\"\n" +
" Object.module_eval(code)\n" +
" end\n" +
"end\n"
end
def run
#print(@codeString)
ObjectSpace.each_object(Class) do | aClass |
if aClass.to_s == @className
eval(@codeString)
end
end
end
end
a string representing the class name). I use it maybe 30 times during my
application run. However I'm concerned because it does an
ObjectSpace.each(Class) call to make sure the specified class exists before
trying to remove any methods. Will this call get slow as a few arrays
containing perhaps a million FixNums get defined by the application in
between calls? The array's data stays around as the calls to my class are
made. I've included the source of the class below. If anyone knows an
efficient way to determine if a class exists given its name in String form
I'd sure appreciate seeing it.
class MethodRemover
def initialize(className)
@className = className
@codeString = "class " + className +"\n" +
" public_instance_methods(false).each do | method |\n" +
" code = \"class #{className} remove_method
:\"\+method\+\" end\"\n" +
" Object.module_eval(code)\n" +
" end\n" +
"end\n"
end
def run
#print(@codeString)
ObjectSpace.each_object(Class) do | aClass |
if aClass.to_s == @className
eval(@codeString)
end
end
end
end