如何获得某种类型的所有方法
问题描述:
我有一个类型T
,我如何获得在REPL中专门用于这种类型的所有方法?我的动机是T
被定义在一个包中,并且可能不容易看到我的意思是从源代码中使用T
。如何获得某种类型的所有方法
综上所述,我想要的东西像
functions(T)
为methods
已经存在,但它需要的功能,我想了解
答
您需要使用methodswith(T)
:
help?> methodswith
search: methodswith
methodswith(typ[, module or function][, showparents])
Return an array of methods with an argument of type typ. If optional showparents
is true, also return arguments with a parent type of typ, excluding type Any.
The optional second argument restricts the search to a particular module or
function.
julia> type Foo end
julia> methodswith(Foo)
0-element Array{Method,1}
julia> foo(::Foo) = nothing
foo (generic function with 1 method)
julia> methodswith(Foo)
1-element Array{Method,1}:
foo(::Foo) at none:1