can
ErrorsCollection

can

Synthesised documentation from type/Metamodel/MROBasedMethodDispatch type/Metamodel/ClassHOW

From type/Metamodel/MROBasedMethodDispatch

See Original text in context

method can($obj$name)

Returns the list of methods of that name the object can do.

From type/Metamodel/ClassHOW

See Original text in context

method can($obj$method-name)

Given a method name, it returns a List of methods that are available with this name.

class A      { method x($a{} };
class B is A { method x()   {} };
say B.^can('x').elems;              # OUTPUT: «2␤» 
for B.^can('x'{
    say .arity;                     # OUTPUT: «1, 2␤» 
}

In this example, class B has two possible methods available with name x (though a normal method call would only invoke the one installed in B directly). The one in B has arity 1 (i.e. it expects one argument, the invocant (self)), and the one in A expects 2 arguments (self and $a).