Created
July 18, 2012 15:43
-
-
Save kourge/3137021 to your computer and use it in GitHub Desktop.
Relaunch current script in MacRuby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Env | |
MACRUBY_FRAMEWORK_BIN = 'MacRuby.framework/Versions/Current/usr/bin/macruby' | |
MACRUBY_CANDIDATES = [ | |
"/System/Library/PrivateFrameworks/#{MACRUBY_FRAMEWORK_BIN}", | |
"/Library/Frameworks/#{MACRUBY_FRAMEWORK_BIN}" | |
] | |
def self.find_macruby | |
MACRUBY_CANDIDATES.each do |path| | |
return path if File.exist?(path) | |
end | |
last_resort = `which macruby` | |
last_resort.empty? ? nil : last_resort | |
end | |
def self.macruby? | |
return false unless Kernel.const_defined?(:RUBY_ENGINE) | |
Kernel.const_get(:RUBY_ENGINE) == 'macruby' | |
end | |
def self.relaunch_in_macruby!(fatal=true) | |
return if self.macruby? | |
macruby = self.find_macruby | |
fail 'Could not find MacRuby' if macruby.nil? and fatal | |
args = [__FILE__] + ARGV | |
Kernel.exec(macruby, *args) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment