«if-then-else alternative to Platform.case» by LightRate
on 22 Jun'16 10:34 in1 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
// Normally, controlling platform specific commands is implemented with Platform.case: ( Platform.case {\osx} { openOS("https://apple.com") } {\linux} { openOS("https://linux.com") } {\unix} { openOS("http://unix.org") } {\windows} { openOS("https://microsoft.com") } ); // But what if you need an 'if-then-else' style of Platform control? // In these situations, the Platform.case method isn't the most elegant, or efficient solution. // Here is an alternative route: if( thisProcess.platform.asSymbol == 'an OSXPlatform', { // true function }, { // false function } )
reception
3 others way to put it in a If:
thisProcess.platform.name == \osx thisProcess.platform.class == OSXPlatform thisProcess.platform.isKindOf(OSXPlatform)
Well done, these are even better than my original solution.
thisProcess.platform.isKindOf(OSXPlatform) reads the most like english, which is a marker of really, really good code.