是否有类似+.method
的方法可以提供可以调用+
的类列表?
答案 0 :(得分:1)
有一个黑客实际上什么都不保证,但你可能想尝试:
▶ ObjectSpace.each_object.select { |obj|
Class === obj && obj.instance_methods.include?(:+)
}
#=> [
# [0] Complex < Numeric,
# [1] Rational < Numeric,
# [2] Time < Object,
# [3] Array < Object,
# [4] Bignum < Integer,
# [5] Float < Numeric,
# [6] Fixnum < Integer,
# [7] String < Object,
# [8] Pathname < Object,
# [9] CodeRay::Tokens < Array