I want to release some code without encouraging an OS X monoculture:
…but I have some nifty but not absolutely essential functionality
which currently I only know how to do on OS X. Is there a dependable
“if platform?(apple)” I can use?
Actually, now that I put it that way, I’m going to write one. But does
anyone know the quickest, cleanest way?
class Kernel
def os_x?
# ???
end
end
The gems discussion recently had somebody who specified the wrong
string indicating Windows for their platform - I wasn’t sure if that
was the poster’s mistake or a weird overabundance of useful
platform-indicative strings in gems or Ruby, but I want to avoid that
same pitfall.
def which_platform?
$RUBY_PLATFORM ||=
case RUBY_PLATFORM.downcase
when /linux|bsd|solaris|hpux|powerpc-darwin/
:unix
when /mswin32|mingw32|bccwin32/
:windows
when /cygwin/
:cygwin
when /java/
:java
else
:other
end
end