Mario moves between platforms with ease, he's brought his tools along to help you do the same
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Mario is super small library to help you with getting from platform to platform with ease!


Mario's main function is providing simple methods to match your current operating system or a group of operating systems. For example if you wanted to know if your code was excuting on some version of Windows

Or a Unix-like operating system


If you want to be more specific you can do that too

Mario::Platform.bsd? # or linux? or windows7? or darwin?

If for some reason you opperating system isn't represented please alert me and/or see the setup for hacking on Mario below, but in the meantime you can force which operating system you would like Mario to report

Mario::Platform.forced = Mario::Platform::Linux

targeted methods

In version 0.1 of Mario, the ability to define platform specific instance method implementations has been added via the class method platform. All you have to do is extend your class with Mario::Tools.

class MyClass
  extend Mario::Tools

  platform :windows do
    def foo
      "I will only work for Windows!"

  platform :linux do
    def foo
      "I will only work for Linux!"

Mario::Platform.forced = Mario::Platform::Windows7 # => "I will only work for Windows!"

Mario::Platform.forced = Mario::Platform::Linux # => "I will only work for Linux!"

Alternatively, if you don't need the flexibility of actual method definitions or multiple methods, you can do the following:

class MyClass
  extend Mario::Tools

  platform :windows, :foo do |param|
    "This is my param on Windows: #{param}"
  platform :linux, :foo do |param|
    "This is my param on Linux: #{param}"

platform value maps

Sometimes you don't need an actual method and you just want to define a platform spefic value for something. With Mario you can do the following:

class MyClass
  extend Mario::Tools
  attr_accessor :my_ivar

  def initialize
    @my_ivar = platform_value_map { :windows => 'Windows!', :linux => 'Linux!' }

Mario::Platform.forced = Mario::Platform::Windows7 # => 'Windows!'

Mario::Platform.forced = Mario::Platform::Linux # => 'Linux!'

platform symbol values

Any class defined in Mario::Platform.targets can be used as symbol for platform and platform_value_map to target a given platform. The following are supported as of version 0.1

>>{ |t| Mario::Platform.klass_to_method(t).to_sym }
=> [:cygwin, :linux, :bsd, :solaris, :tiger, :leopard, :snowleopard, :darwin, :windows7, :windowsnt]

along with :windows and :nix (just as you can query for those via and Mario::Platform.nix?).


When testing your app you'll want to force the platform that mario reports to test your platform specific methods. In order to accomplish this make sure to defer the method definition done by the platform class method in the following manner.

require 'my_class'

This will allow you to force the platform and THEN define the methods on your classes manually so that you can test them for various platforms.

Mario::Platform.forced = Mario::Platform::Windows7
MyClass.define_platform_methods! # => "Windows!"

The blocks are stored so that define_platform_methods! can be called many times after forcing the platform to provide different results.

Mario::Platform.forced = Mario::Platform::Windows7
MyClass.define_platform_methods! # => "Windows!"

Mario::Platform.forced = Mario::Platform::Linux
MyClass.define_platform_methods! # => "Linux!"

IMPORTANT The above does NOT apply to platform_value_map, if you want the above functionality its best to assign the values from functions defined in the above manner


Mario has different abilities with different hats, each hat is tied to the current operating system. To start Mario can only escape file paths properly for nix operating systems and there's still testing to be done on the windows version, but there will be more to come. To make use of Mario's version of his abilities on your platform you might do the following:

Mario::Platform.current.shell_escape_path('C:\Some Path\With Some Spaces.filext')

Its important to note that shell_escape_path is an actual method and not what Mario would do when confronted with an oncoming koopa shell.


If you want to hack on mario, and I would grateful for any patches to for all those dark little corners that need light shone on them, just do the following from your project directory after forking and cloning:

$ bundle install
$ bundle lock
$ rake test

If all is well you're ready to roll.


See the license file for more information.