forked from supercollider/supercollider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Method.schelp
115 lines (83 loc) · 3.77 KB
/
Method.schelp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
class::Method
categories::Core>Kernel
summary:: Code that implements an operation upon instances of a Class.
related:: Classes/Class
description::
link::Classes/Method::s are created for each method defined with a class.
For a definition of a method,
see link::Guides/Intro-to-Objects:: and link::Guides/WritingClasses::.
subsection:: Related Keywords
method:: thisMethod
The global pseudo-variable code::thisMethod:: always evaluates to the enclosing Method in a class definition, much like code::thisFunction::.
When executed outside that context, it returns link::Classes/Interpreter#-functionCompileContext::, the method within which all interpreted code executes.
code::
// if the following code were compiled as part of the class library:
SomeClass {
methodThatPostsItself {
thisMethod.postln;
}
}
// then running this would post
// "SomeClass:methodThatPostsItself"
a = SomeClass.new;
a.methodThatPostsItself;
::
code::thisMethod:: is frequently used to pass information to error-throwing methods. For example, the implementation of code::Nil.new:: is:
code::
*new { ^this.shouldNotImplement(thisMethod) }
::
See also: link::Classes/Function#.thisFunction#thisFunction::.
instanceMethods::
method::ownerClass
returns::
If the receiver is an instance method, the owner class is the class for this instance.
For a class method, it is the class of the class, whose name is prefixed with "Meta_".
code::
m = Array.findRespondingMethodFor('reverse');
m.ownerClass; // Array
m = Array.class.findRespondingMethodFor(\new);
m.ownerClass; // Meta_Array
::
method::name
returns::
A link::Classes/Symbol:: which is the name of the Method.
method::primitiveName
returns::
A link::Classes/Symbol:: which contains the name of the primitive function that implements the Method,
if there is one, otherwise returns link::Classes/Nil::.
method::argumentNamesForCall
Returns the argument names as needed for calling the function as an link::Classes/Array::.
This will remove any internal arguments include 'this'.
method:: filenameSymbol
returns::
A link::Classes/Symbol:: which is the full path of the source file that this method is defined in.
method::makePerformableArray
This is used internally by link::Classes/Object#-performWith:: which is sufficient for all uses and recommended over link::#-makePerformableArray::.
Returns an array that can be passed to link::Classes/Object#-performList:: along with the selector.
Both keyword and non-keyword arguments may be provided at the same time.
Errors are thrown if: a value for an argument is present in both the code::argumentsArray:: and the code::keywordArgumentPairs:: (argument collision),
if a keyword argument's name cannot be found (unknown keyword),
and if too many arguments are given to code::argumentsArray:: (too many arguments).
Variable arguments are best placed with a keyword argument.
However, if the code::keywordArgumentPairs:: is empty and all arguments in the code::argumentsArray:: are present, any extra arguments in code::argumentsArray:: will be passed to the variable argument, if present.
Please note, that variable arguments are unpacked and individually appened to the end of the array, not contained in their own array.
argument::argumentsArray
Arguments as an link::Classes/Array::.
argument::keywordArgumentPairs
Keyword arguments as any link::Reference/Key-Value-Pairs:: structure.
returns::Arguments as an link::Classes/Array::.
discussion::
code::
a = "meow MEOW woof bahh bahh Meow";
// how a user might call a method
a.findAll("meow", ignoreCase: true);
// using makePerformableArray directly, not recommended
(
var args = String
.findRespondingMethodFor('findAll')
.makePerformableArray(["meow"], [ignoreCase: true]);
a.performList('findAll', args);
)
// using performWith, recommended
a.performWith('findAll', ["meow"], [ignoreCase: true]);
::