执行motion support命令报错:URI模块无escape方法(NoMethodError)
解决RubyMotion中
motion support命令的URI.escape未定义错误 问题描述
执行motion support命令时触发如下错误:
qppn@MacBook-Pro hello % motion support /Library/RubyMotion/lib/motion/command.rb:140:in guess_email_address': undefined method escape' for URI:Module (NoMethodError) URI.escape(`git config --get user.email`.strip) ^^^^^^^ from /Library/RubyMotion/lib/motion/command/support.rb:36:in `run' from /Library/RubyMotion/vendor/CLAide/lib/claide/command.rb:277:in `run' from /Library/RubyMotion/lib/motion/command.rb:106:in `run' from /usr/local/bin/motion:22:in `<main>'
错误本质是Ruby 3.0+版本已移除URI.escape方法,但RubyMotion旧版本代码仍在调用该废弃方法。
修复步骤
- 打开RubyMotion的命令处理文件:
open /Library/RubyMotion/lib/motion/command.rb - 定位到第140行的
guess_email_address方法,找到目标代码行:URI.escape(`git config --get user.email`.strip) - 将其替换为Ruby 3.0+支持的官方替代方法:
URI.encode_www_form_component(`git config --get user.email`.strip) - 保存文件后,重新执行
motion support命令即可正常运行。
补充说明
URI.escape在Ruby 2.7版本已被标记为废弃,Ruby 3.0正式移除该方法。URI.encode_www_form_component是官方推荐的替代方案,能够正确处理邮箱地址这类字符串的URL编码需求。
内容的提问来源于stack exchange,提问作者Nazi
相关产品推荐
相关产品推荐

