I've got a ruby script on this Mac, that I want to distribute to Windows users. I'm trying to use the gem Rubyscript2exe to make an executable, but when I run the following command:
$ rubyscript2exe jabberbot.rb
I get the folowing error:
/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 is
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)
Line 19 of /usr/bin/rubyscript2exe is
load Gem.bin_path('rubyscript2exe', 'rubyscript2exe', version)
New issue:
After replacing the code as answered I am now getting this error:
/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
Your problem is due to a specification change made in ruby 1.8.7 and ruby1.9. $0
refers to the program name, but it became frozen. Are you using the newest version of rubyscript2exe
? If not, try the newest version. If the problem is still there, then, as suggested by rubyscript2exe, change the line:
$0.replace(realstuff) if isapplication
to these:
# $0.replace(realstuff) if isapplication # original
$__0 = realstuff if isapplication # added
alias $__0 $0 # added
alias $0 $_0 # added
This link may help: http://www.ruby-forum.com/topic/3173966
You can use ocra: http://ocra.rubyforge.org/
This way:
gem install ocra
ocra --console myapp.rb
精彩评论