Ruby在尝试使用Rudyscript2exe时出现“无法修改冻结的字符串”错误

| 我在这台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 / ruby​​script2exe的第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
    
已邀请:
您的问题是由于在ruby 1.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
    
该链接可能会有所帮助:http://www.ruby-forum.com/topic/3173966 您可以使用ocra:http://ocra.rubyforge.org/ 这条路:
gem install ocra
ocra --console myapp.rb
    

要回复问题请先登录注册