Created
September 7, 2010 02:43
-
-
Save Sutto/567789 to your computer and use it in GitHub Desktop.
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
class X | |
def self.ruby_command | |
@@ruby_command ||= begin | |
real_rvm_ruby = self.rvm_ruby_string | |
real_rvm_path = self.rvm_path | |
filename = nil | |
if !real_rvm_ruby.nil? && !real_rvm_path.nil? | |
rvm_ruby = File.join(real_rvm_path, "wrappers", real_rvm_ruby, "ruby") | |
filename = rvm_ruby if File.exists?(rvm_ruby) | |
end | |
filename ||= Config::CONFIG['bindir'] + '/' + Config::CONFIG['RUBY_INSTALL_NAME'] + Config::CONFIG['EXEEXT'] | |
filename | |
end | |
end | |
# Returns the current ruby string for the loaded ruby | |
def self.rvm_ruby_string | |
gem_home = ENV['GEM_HOME'].to_s.strip | |
if !gem_home.empty? && gem_home =~ /rvm\/gems\// | |
File.basename(gem_home) | |
else | |
matching_path = $:.select { |item| item =~ /rvm\/rubies/ }.first | |
matching_path.to_s.gsub(/^.*rvm\/rubies\//, '').split('/')[0] | |
end | |
end | |
# Get a value for the current rvm path. | |
def self.rvm_path | |
[ENV['rvm_path'], "~/.rvm", "/usr/local/rvm"].each do |path| | |
next if path.nil? | |
path = File.expand_path(path) | |
return path if File.directory?(path) | |
end | |
return nil | |
end | |
end | |
# ALTERNATIVE | |
class Y | |
def self.ruby_command | |
@@ruby_command ||= begin | |
if !ENV['MY_RUBY_HOME'].nil? | |
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME'])) | |
$LOAD_PATH.unshift File.join(rvm_path, "lib") | |
require 'rvm' | |
rvm_ruby = File.join(rvm_path, "wrappers", RVM::Environment.current_environment_id, "ruby") | |
filename = rvm_ruby if File.exists?(rvm_ruby) | |
end | |
filename ||= Config::CONFIG['bindir'] + '/' + Config::CONFIG['RUBY_INSTALL_NAME'] + Config::CONFIG['EXEEXT'] | |
filename | |
end | |
end | |
end | |
puts "X: #{X.ruby_command}" | |
puts "Y: #{Y.ruby_command}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment