Ruby knows the OS it was compiled on, and what it's running on, because it has to be aware of path delimiters, line-ending characters, etc. We can find out about what it knows using built-in constants and/or modules.
Using the RUBY_PLATFORM
constant:
On Mac OSX:
RUBY_PLATFORM # => "x86_64-darwin13.0"
On Linux:
RUBY_PLATFORM # => "x86_64-linux"
You can also use Gem::Platform:
On Mac OSX:
Gem::Platform.local # => #<Gem::Platform:0x3fe859440ef4 @cpu="x86_64", @os="darwin", @version="13">
Gem::Platform.local.os # => "darwin"
And on Linux:
Gem::Platform.local # => #<Gem::Platform:0x13e0b60 @cpu="x86_64", @os="linux", @version=nil>
Gem::Platform.local.os # => "linux"
And then there's the RbConfig module that comes with Ruby:
On Mac OS:
RbConfig::CONFIG['target_cpu'] # => "x86_64"
RbConfig::CONFIG['target_os'] # => "darwin13.0"
RbConfig::CONFIG['host_cpu'] # => "x86_64"
RbConfig::CONFIG['host_os'] # => "darwin13.4.0"
And on Linux:
RbConfig::CONFIG['target_cpu'] # => "x86_64"
RbConfig::CONFIG['target_os'] # => "linux"
RbConfig::CONFIG['host_cpu'] # => "x86_64"
RbConfig::CONFIG['host_os'] # => "linux-gnu"
A quick search returns a number of hits for this, including many here on Stack Overflow.