如何获得可以调用方法的对象列表?

How do you get the list of objects on which a method can be called?

是否有像 +.method 这样的方法可以给出可以调用 + 的类列表?

有一个 hack 实际上没有任何保证,但您可能想尝试一下:

▶ 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