Reputation: 57
Is there a method like +.method
which can give a list of classes on which +
can be called upon?
Upvotes: 0
Views: 28
Reputation: 121020
There is a hack which actually guarantees nothing, but you might want to try:
▶ 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
Upvotes: 1