Reflection/List methods: Difference between revisions

Add Ecstasy example
imported>Arakov
(Add Ecstasy example)
 
(3 intermediate revisions by 2 users not shown)
Line 118:
opEquals
factory</pre>
 
=={{header|Ecstasy}}==
For any object, the type of that object provides access to its methods and functions:
 
<syntaxhighlight lang="ecstasy">
module test {
void run() {
@Inject Console console;
 
String[] names = &this.actualType.multimethods.keys.toArray();
console.print($"Method/function names on {this}: {names}");
 
Method[] methods = &this.actualType.methods;
console.print($"The methods of {this}: {methods}");
 
Function[] functions = &this.actualType.functions;
console.print($"The functions of {this}: {functions}");
}
}
</syntaxhighlight>
 
{{out}}
<pre>
x$ xec test
Method/function names on test: [toString, makeImmutable, to, estimateStringLength, appendTo, exTo, toEx, exToEx, isModuleImport, classForName, typeForName, run, hashCode, maxOf, notGreaterThan, compare, equals, minOf, notLessThan]
The methods of test: [String toString(), immutable Object makeImmutable(), Range<Orderable> to(Orderable that), Int estimateStringLength(), Appender<Char> appendTo(Appender<Char> buf), Range<Orderable> exTo(Orderable that), Range<Orderable> toEx(Orderable that), Range<Orderable> exToEx(Orderable that), conditional Module isModuleImport(), conditional Class classForName(String name), conditional Type typeForName(String name), void run()]
The functions of test: [Int hashCode(Type<Package> CompileType, CompileType value), CompileType maxOf(Type<Orderable> CompileType, CompileType value1, CompileType value2), CompileType notGreaterThan(Type<Orderable> CompileType, CompileType value1, CompileType value2), Ordered compare(Type<Const> CompileType, CompileType value1, CompileType value2), Boolean equals(Type<Package> CompileType, CompileType value1, CompileType value2), CompileType minOf(Type<Orderable> CompileType, CompileType value1, CompileType value2), CompileType notLessThan(Type<Orderable> CompileType, CompileType value1, CompileType value2)]
</pre>
 
=={{header|Elena}}==
Line 136 ⟶ 164:
var o := new MyClass();
o.__getClass().__getMessages().forEach::(p)
{
console.printLine("o.",p)
Line 143 ⟶ 171:
{{out}}
<pre>
o.equal[2]
o.notequal[2]
o.toPrintable[1]
Line 1,370 ⟶ 1,399:
 
Note that, since attributes are stored internally as a map, the order in which the method names appear is undefined.
<syntaxhighlight lang="ecmascriptwren">#! instance_methods(m, n, o)
#! instance_properties(p, q, r)
class C {
162

edits