How to test if something is a UGen or UGen class

CombN.isUGen == false while CombN.ar.isUGen == true because isUGen in instance method. But sometimes you need to test for both. So what’s the idiomatic way to do this in SC?

I had attempted something like

+ Object {
	*isUGenClass { ^false }
}

+ UGen {
	*isUGenClass { ^true }
}

which has the advantage that these (meaning the pre-existing isUGen and my added isUGenClass) are separate tests, but that makes the subsequent logic very hairy. So would it be ok to have a class method also called isUGen, i.e define *isUGen? Would that break some other implicit code assumptions or at least naming conventions in SC?

You can do the following:

SimpleNumber.isKindOf(UGen.class); // false
UGen.isKindOf(UGen.class); // true
SinOsc.isKindOf(UGen.class); // true
1 Like

Thanks, I’ll consider that. As a quick fix I did:

+ Object {
	*isUGenClass { ^false }
	isUGenClass { ^false } // the fix
}

+ UGen {
	*isUGenClass { ^true }
	isUGenClass { ^false } // redundant actually, but for clarity
}

Which fixes my patch, but does feel a bit kludgy to read.

That’s still not a single test though because

CombN.ar.isKindOf(UGen.class) // false

But I guess one can write

x.isKindOf(UGen.class) or: { x.isUGen }

for the combo test. Also equivalent with the above is

x.isKindOf(UGen.class) or: { x.isKindOf(UGen) } 

and the latter is probably slightly less confusing to read as it’s using the same API twice but with different args, so a bit more clear the tests aren’t the same.