atom feed18 messages in org.ruby-lang.ruby-dev[ruby-dev:39755] RbConfig.rubybin
FromSent OnAttachments
Tanaka AkiraNov 22, 2009 7:23 pm 
Kouhei SutouNov 22, 2009 7:37 pm 
Tanaka AkiraNov 30, 2009 1:26 am 
KOSAKI MotohiroNov 30, 2009 2:28 am 
Kouhei SutouNov 30, 2009 4:39 am 
Akinori MUSHANov 30, 2009 4:41 am 
KOSAKI MotohiroNov 30, 2009 5:29 pm 
KOSAKI MotohiroNov 30, 2009 5:37 pm 
Shugo MaedaNov 30, 2009 7:02 pm 
Kouhei SutouDec 1, 2009 5:54 am 
Shugo MaedaDec 1, 2009 7:11 am 
YuguiDec 1, 2009 10:11 pm 
Kouhei SutouDec 2, 2009 5:01 am 
Kouhei SutouDec 2, 2009 5:09 am 
Tanaka AkiraDec 11, 2009 10:48 pm 
Tanaka AkiraDec 23, 2009 7:30 am 
KOSAKI MotohiroDec 23, 2009 7:17 pm 
Tanaka AkiraDec 31, 2009 7:07 am 
Subject:[ruby-dev:39755] RbConfig.rubybin
From:Tanaka Akira (ak@fsij.org)
Date:Nov 22, 2009 7:23:07 pm
List:org.ruby-lang.ruby-dev

ruby コマンドのパス名を返す RbConfig.rubybin というメソッド を用意するのはどうでしょうか。

現在 ruby コマンドのパス名を得るのには、

File.join( RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"] )

と記述する必要があります。

これはとても覚えていられないので、(そして EXEEXT はいかにも 忘れそうなので) ひとつのメソッドで提供しておくのがいいんじゃ ないでしょうか。

なお、これが使われるケースは ruby の配布の中で少なくとも

lib/webrick/httpservlet/cgihandler.rb benchmark/report.rb benchmark/runc.rb test/ruby/envutil.rb tool/eval.rb

があります。

% svn diff --diff-cmd diff -x '-u -p' Index: tool/mkconfig.rb =================================================================== --- tool/mkconfig.rb (revision 25882) +++ tool/mkconfig.rb (working copy) @@ -201,6 +201,14 @@ print <<EOS CONFIG.each_value do |val| RbConfig::expand(val) end + + # returns the absolute pathname of the ruby command. + def RbConfig.rubybin + File.join( + RbConfig::CONFIG["bindir"], + RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"] + ) + end end Config = RbConfig # compatibility for ruby-1.8.4 and older. CROSS_COMPILING = nil unless defined? CROSS_COMPILING Index: lib/webrick/httpservlet/cgihandler.rb =================================================================== --- lib/webrick/httpservlet/cgihandler.rb (revision 25882) +++ lib/webrick/httpservlet/cgihandler.rb (working copy) @@ -17,9 +17,7 @@ module WEBrick module HTTPServlet

class CGIHandler < AbstractServlet - Ruby = File::join(RbConfig::CONFIG['bindir'], - RbConfig::CONFIG['ruby_install_name']) - Ruby << RbConfig::CONFIG['EXEEXT'] + Ruby = RbConfig.rubybin CGIRunner = "\"#{Ruby}\"
\"#{WEBrick::Config::LIBDIR}/httpservlet/cgi_runner.rb\""

def initialize(server, name) Index: benchmark/report.rb =================================================================== --- benchmark/report.rb (revision 25882) +++ benchmark/report.rb (working copy) @@ -24,9 +24,7 @@ def exec_command type, file, w end

def benchmark cmd - rubybin = ENV['RUBY'] || File.join( - RbConfig::CONFIG["bindir"], - RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"]) + rubybin = ENV['RUBY'] || RbConfig.rubybin

IO.popen(rubybin, 'r+'){|io| io.write cmd Index: benchmark/runc.rb =================================================================== --- benchmark/runc.rb (revision 25882) +++ benchmark/runc.rb (working copy) @@ -5,9 +5,7 @@ require 'benchmark' require 'rbconfig'

-$rubybin = ENV['RUBY'] || File.join( - RbConfig::CONFIG["bindir"], - RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"]) +$rubybin = ENV['RUBY'] || RbConfig.rubybin

def runfile file puts file Index: tool/eval.rb =================================================================== --- tool/eval.rb (revision 25882) +++ tool/eval.rb (working copy) @@ -3,9 +3,7 @@ require 'rbconfig' require 'fileutils' require 'pp'

-Ruby = ENV['RUBY'] || - File.join(RbConfig::CONFIG["bindir"], - RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"]) +Ruby = ENV['RUBY'] || RbConfig.rubybin #

OPTIONS = %w{ Index: test/ruby/envutil.rb =================================================================== --- test/ruby/envutil.rb (revision 25882) +++ test/ruby/envutil.rb (working copy) @@ -22,10 +22,7 @@ module EnvUtil end begin require "rbconfig" - File.join( - RbConfig::CONFIG["bindir"], - RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"] - ) + RbConfig.rubybin rescue LoadError "ruby" end