Reputation: 55
I'm writing a small program that modifies a method during run-time in squeak.
I saw that in squeak there is a method called getSource
(defined in CompiledMethod class), that returns the source code of the compiled method.
How do I get the source code of a method if my input is a Symbol that is corresponding to a method?
Upvotes: 2
Views: 259
Reputation: 3110
You should know the class in which the method is defined, then you can access the CompiledMethod
via, eg,
theClass >> methodSelectorSymbol
or
theClass compiledMethodAt: methodSelectorSymbol
with theClass
being the class with the method and methodSelectorSymbol
is the Symbol that corresponds to the method, ie, your input.
There are further approaches, too.
For example,
theClass lookupSelector: methodSelectorSymbol
not only searches in theClass
but also in its superclasses.
However, all approaches require that you give a class as starting point.
Upvotes: 3