Ruby 在尝试使用 Rudyscript2exe 时出现 "can' t 修改卡住字符串“错误

标签 ruby rubygems

我在这台 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

最佳答案

您的问题是由于 ruby​​ 1.8.7 和 ruby​​1.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 时出现 "can' t 修改卡住字符串“错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5657880/

相关文章:

ruby-on-rails - 如何在 RSpec 中使用 class_double stub 类方法?

html - 如何使 Nokogiri 透明地返回未触及/编码的 Html 实体?

Ruby 1.9.2 向后兼容 1.8.7?

ruby-on-rails - Ruby on Rails 的 Jira API gem?

ruby-on-rails - Snow Leopard ruby​​gems mysql2 和 ruby​​ on Rails 的 MAMP 配置问题

ruby - 如何 reshape Ruby 数组

ruby-on-rails - rails : Mapping root_url to an external url

ruby-on-rails - Docker 和 Rails | bundler : command not found: rails

Ruby 访问对象的 'key'?

ruby - 在 Ruby 中执行多个要求的最佳方法是什么?