Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documenting how to obtain static methods for a type #6938

Merged
merged 4 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion distribution/lib/Standard/Base/0.0.0-dev/src/Meta.enso
Original file line number Diff line number Diff line change
Expand Up @@ -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...`:
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved

Meta.meta Integer . methods

> Example
All static mehtods to invoke on `Integer` as
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
`Integer.method_name...`:

Meta.meta (Meta.type_of Integer) . methods


methods : Vector
methods self =
Vector.from_polyglot_array (get_type_methods self.value)
Expand Down
11 changes: 11 additions & 0 deletions test/Tests/src/Semantic/Meta_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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']
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved

Test.specify "methods of Integer" <|
Meta.meta Integer . methods . sort . should_equal ['round', 'truncate']
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved

Test.specify "static methods of Integer" <|
Meta.meta (Meta.type_of Integer) . methods . sort . should_equal ['parse', 'parse_builtin', 'round', 'truncate']
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved

Test.specify "should correctly handle Java values" <|
java_meta = Meta.meta Random.new
java_meta . should_be_a Meta.Polyglot
Expand Down