class Test
end
at_exit do
ObjectSpace.each_object(Class) do |klass|
if klass.superclass == Test
klass.new.methods.grep(/^test/) do |method|
klass.new.__send__(method)
end
end
end
end
class A < Test
def test_a_1
puts "a_1"
end
def test_a_2
puts "a_2"
end
end
class B < Test
def test_b_1
puts "b_1"
end
def test_b_2
puts "b_2"
end
end
ruby的ObjectSpace.each_object的用法
最新推荐文章于 2024-08-17 22:25:52 发布