That’s the trickiest thing; actually I’d say that it’s generally impossible, but not for lack of tools, but because by definition there is no closed list of “methods for X
” or “methods for Foo
”.
methodswith(X)
may help you get a list of methods that you would like to extend at some point, and with a bit of metaprogramming you might extend all of them at once so that they work for Foo
instead of X
.(*) But then, maybe you do using Bar
, which defines new methods for X
, and your “extension” becomes incomplete.
And the “bad news” is that there is no way at all to anticipate what new methods may come from other packages. (Of course “bad news” only for the purpose of what we are discussing; in general that’s what makes composability easier.)
(*) Even for a limited list of “methods for X
”, extending them so that they take Foo
instead of X
is not always straightforward. For instance, how would you extend *(::X, ::X)
? Shall it be *(::Foo, ::Foo)
, or also other combinations with X
and Foo
?