[Cuis-dev] SVGs and using reflection to call class methods

Ezequiel Birman ebirman77 at gmail.com
Wed Jun 19 19:37:35 PDT 2024


Hi,

The receiver is not the metaclass but its `soleInstance` i.e SVGMainMorph.

class := SVGMainMorph.
selectors := class class selectorsInCategory: #examples.

selectors do: [ :selector |
    (selector beginsWith: 'example') ifTrue: [
        (class perform: selector) openInWorld
    ]
]

On Thu, 20 Jun 2024 at 01:44, Mark Volkmann via Cuis-dev <
cuis-dev at lists.cuis.st> wrote:

> Here are my notes on working with SVGs in Cuis:
>
> - Open a terminal.
>
> - Clone the following Git repositories from Cuis Smalltalk:
>
>   - https://github.com/Cuis-Smalltalk/Numerics.git
>   - https://github.com/Cuis-Smalltalk/SVG.git
>
> - Open a Workspace window and install the packages `LinearAlgebra` and
> `SVG.
>
>   For each package, enter `Feature require: '{package-name}'` and "Do it".
>
> - Enter `SVGMainMorph exampleTiger openInWorld` and "Do it".
>
> Now that I have this working, I wanted to see if I could use reflection
> to open all the examples.
> I know I can just do this: SVGMainMorph openAllExamples SVGMainMorph.
> But I wanted to see if I could do it with reflection. Here is what I tried.
>
> metaclass := SVGMainMorph class.
> selectors := metaclass allMethodsInCategory: #examples.
> selectors do: [ :selector |
>     (selector beginsWith: 'example') ifTrue: [
>         (MessageSend receiver: metaclass selector: selector) openInWorld
>     ]
> ].
>
> This gives me "MessageNotUnderstood" on the send of openInWorld because
> apparently the code "MessageSend receiver: metaclass selector: selector"
> does not return a Morph. It's not clear to me why it doesn't.
>
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240620/8afadb99/attachment-0001.htm>


More information about the Cuis-dev mailing list