我在这台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
答案 0 :(得分:1)
您的问题是由于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
答案 1 :(得分:0)
此链接可能有所帮助:http://www.ruby-forum.com/topic/3173966
您可以使用ocra:http://ocra.rubyforge.org/
这样:
gem install ocra
ocra --console myapp.rb