我在这台Mac电脑上有一个Ruby脚本,我想分发给Windows用户。我试图使用gem Rubyscript2exe来生成可执行文件,但是当我运行以下命令时:

$ rubyscript2exe jabberbot.rb

我得到以下错误:
/Library/Ruby/Gems/1.8/gems/rubyscript2exe-0.5.3/bin/rubyscript2exe:5:in `replace': can't modify frozen string (TypeError)
from /Library/Ruby/Gems/1.8/gems/rubyscript2exe-0.5.3/bin/rubyscript2exe:5
from /usr/bin/rubyscript2exe:19:in `load'
from /usr/bin/rubyscript2exe:19

/Library/Ruby/Gems/1.8/Gems/rubyscript2exe-0.5.3/bin/rubyscript2exe是
gemdir  = File.expand_path("..", File.dirname(__FILE__))
realstuff   = File.expand_path("realstuff.rb", gemdir)
isapplication   = File.basename(File.dirname(__FILE__)) == "bin"

$0.replace(realstuff)   if isapplication

load(realstuff)

/usr/bin/rubyscript2exe的第19行是
load Gem.bin_path('rubyscript2exe', 'rubyscript2exe', version)

新版本:
在将代码替换为已回答的代码后,我现在收到以下错误:
/private/tmp/tar2rubyscript.d.4970.1/rubyscript2exe/rubyscript2exe.rb:37:in `expand_path': can't convert nil into String (TypeError)
from /private/tmp/tar2rubyscript.d.4970.1/rubyscript2exe/rubyscript2exe.rb:37:in `appdir'
from /private/tmp/tar2rubyscript.d.4970.1/rubyscript2exe/rubyscript2exe.rb:96
from /private/tmp/tar2rubyscript.d.4970.1/rubyscript2exe/init.rb:2:in `load'
from /private/tmp/tar2rubyscript.d.4970.1/rubyscript2exe/init.rb:2
from /Library/Ruby/Gems/1.8/gems/rubyscript2exe-0.5.3/realstuff.rb:632:in `load'
from /Library/Ruby/Gems/1.8/gems/rubyscript2exe-0.5.3/realstuff.rb:632
from /Library/Ruby/Gems/1.8/gems/rubyscript2exe-0.5.3/realstuff.rb:577:in `newlocation'
from /Library/Ruby/Gems/1.8/gems/rubyscript2exe-0.5.3/realstuff.rb:505:in `newlocation'
from /Library/Ruby/Gems/1.8/gems/rubyscript2exe-0.5.3/realstuff.rb:472:in `newlocation'
from /Library/Ruby/Gems/1.8/gems/rubyscript2exe-0.5.3/realstuff.rb:505:in `newlocation'
from /Library/Ruby/Gems/1.8/gems/rubyscript2exe-0.5.3/realstuff.rb:577:in `newlocation'
from /Library/Ruby/Gems/1.8/gems/rubyscript2exe-0.5.3/realstuff.rb:619
from /Library/Ruby/Gems/1.8/gems/rubyscript2exe-0.5.3/bin/rubyscript2exe:11:in `load'
from /Library/Ruby/Gems/1.8/gems/rubyscript2exe-0.5.3/bin/rubyscript2exe:11
from /usr/bin/rubyscript2exe:19:in `load'
from /usr/bin/rubyscript2exe:19

最佳答案

您的问题是由于ruby1.8.7和ruby1.9中的规范更改造成的$0指程序名,但已冻结您正在使用最新版本的rubyscript2exe?如果没有,试试最新的版本。如果问题仍然存在,则按照rubyscript2exe的建议更改行:

$0.replace(realstuff)   if isapplication

致:
# $0.replace(realstuff)   if isapplication   # original
$__0 = realstuff   if isapplication          # added
alias $__0 $0                                # added
alias $0 $_0                                 # added

关于ruby - 尝试使用Rudyscript2exe时,Ruby出现“无法修改卡住的字符串”错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5657880/

10-11 01:36