ruby的ObjectSpace.each_object的用法
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
点亮测试人生!QQ:408129370
百度阅读电子书地址:http://yuedu.baidu.com/ebook/f6dbb2a2f01dc281e53af0f3
讨论QQ群:536192476
个人公众号:
百度阅读电子书地址:http://yuedu.baidu.com/ebook/f6dbb2a2f01dc281e53af0f3
讨论QQ群:536192476
个人公众号: