mirror of
https://github.com/enso-org/enso.git
synced 2024-12-27 07:32:38 +03:00
Documenting how to obtain static methods for a type (#6938)
Fixes #6748 by documenting how to obtain all static methods available on a `Type`.
This commit is contained in:
parent
27feaf6bc5
commit
f1bdcbb534
@ -36,7 +36,26 @@ type Type
|
||||
|
||||
## ADVANCED
|
||||
|
||||
Returns a vector of `Meta.Constructor` for this type
|
||||
Returns a vector of method names that can be invoked
|
||||
on instances of this type.
|
||||
? Static Methods
|
||||
|
||||
To obtain list of _static methods_ on a given type
|
||||
use `Meta.type_of`.
|
||||
|
||||
> Example
|
||||
All instance methods to invoke on `Integer` as
|
||||
`(v:Integer) v.method_name...`:
|
||||
|
||||
Meta.meta Integer . methods
|
||||
|
||||
> Example
|
||||
All static methods to invoke on `Integer` as
|
||||
`Integer.method_name...`:
|
||||
|
||||
Meta.meta (Meta.type_of Integer) . methods
|
||||
|
||||
|
||||
methods : Vector
|
||||
methods self =
|
||||
Vector.from_polyglot_array (get_type_methods self.value)
|
||||
|
@ -30,9 +30,13 @@ type My_Type
|
||||
@b (self -> self.foo)
|
||||
other_method self a = a
|
||||
|
||||
create foo bar = My_Type.Value foo bar 3
|
||||
|
||||
@self ("se" + "lf")
|
||||
My_Type.my_method self = self.foo + self.bar + self.baz
|
||||
|
||||
My_Type.factory = My_Type.create 1 2
|
||||
|
||||
@a (test_method 3 4)
|
||||
@b (Test_Type.Value 49)
|
||||
@c (Error.throw "Error Value")
|
||||
@ -247,9 +251,16 @@ spec =
|
||||
|
||||
methods.sort . should_equal ['bar', 'baz', 'first_method', 'foo', 'my_method', 'other_method', 'second_method']
|
||||
|
||||
Test.specify "static methods of MyType" <|
|
||||
methods = Meta.meta (Meta.type_of My_Type) . methods
|
||||
methods.sort . should_equal ['Value', 'create', 'factory', 'first_method', 'my_method', 'other_method', 'second_method']
|
||||
|
||||
Test.specify "methods of Integer" <|
|
||||
Meta.meta Integer . methods . sort . should_equal ['round', 'truncate']
|
||||
|
||||
Test.specify "static methods of Integer" <|
|
||||
Meta.meta (Meta.type_of Integer) . methods . sort . should_equal ['parse', 'parse_builtin', 'round', 'truncate']
|
||||
|
||||
Test.specify "should correctly handle Java values" <|
|
||||
java_meta = Meta.meta Random.new
|
||||
java_meta . should_be_a Meta.Polyglot
|
||||
|
Loading…
Reference in New Issue
Block a user