[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sc-users] Re: Referring to class methods as functions



In my example, of course on the left-hand side of the assignment I meant to write:

this.preProcessor = ...
(or equivalently thisProcess.interpreter.preprocessor = …)

I see what I was trying probably doesn't work because the thing return (from MyClass.class.findMethod('myMethod')) is not a regular Function, it's a Method. Is there a way to call a (class) Method as though it were a regular (closed) Function? For instance methods, I understand that you'd need to pass an instance of the object, but for class methods it should be capable of being "free-standing"...no?

Anyhow, I guess it doesn't matter, since doing the following works fine -- just wanted to know if there was another way by just assigning the class method:

this.preProcessor = MyClass.myMethod(_);

Thanks,
Glen.


On Sun, Nov 24, 2019 at 4:56 PM Glen F <holaglen@xxxxxxxxx> wrote:
Hi there, is there a trick to refer to class methods as though they were regular functions?  For example I'm trying to take a class method (which takes a string argument and returns a string) and assign it to preProcess (the Interpreter preprocessor callback function).

It works fine if I wrap it in a function, but can I somehow directly set it?

Evaluating the following seems to mess things up:

this.preProcess = MyClass.class.findMethod('myMethod');

but this works fine:

this.preProcess = { |code| MyClass.myMethod(code) };

Thanks,
Glen.

P.S. MyClass.class.findMethod('myMethod') does correctly return my class method, not 'nil'.