Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all methods for a type

Tags:

I have a type T, how can I get all methods that are specialized to this type in the REPL? My motivation is that T is defined in a package and it may not be easy to see what I am meant to do with T from the source code.

In summary, I'd want something like

functions(T) 

as methods already exists but it requires the functions I want to find out about

like image 490
Fred Schoen Avatar asked Jul 25 '16 09:07

Fred Schoen


People also ask

How do you get all methods in a class?

Method 1 – Using the dir() function to list methods in a class. To list the methods for this class, one approach is to use the dir() function in Python. The dir() function will return all functions and properties of the class. Let's see what happens if we try it for MyClass .

How do I check for built in methods in Python?

Check with the built-in function dir() The built-in function dir() returns a list of names of attributes, methods, etc. of the object specified in the argument. You can get a list of names of built-in objects, such as built-in functions and constants, by passing the builtins module or __builtins__ to dir() .

How do you print a class method in Python?

Print an Object in Python Using the __str__() Method Now, let's define the __str__() method of our example class ClassA and then try to print the object of the classA using the print() function. The print() function should return the output of the __str__() method.


Video Answer


1 Answers

You need to use 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 
like image 158
HarmonicaMuse Avatar answered Oct 07 '22 00:10

HarmonicaMuse