系统中的第一个参数错误

Jua*_*tas 3 ruby system

在git存储库中.我想得到针对远程origin主分支的提交数量:

remote = 'origin'
system %W[git rev-list HEAD...#{remote}/master --count]
Run Code Online (Sandbox Code Playgroud)

这将导致ArgumentError: wrong first argument.

但是git rev-list HEAD...#{remote}/master --count有效.

我的第一个论点有什么问题?

Jua*_*tas 5

需要使用splat运算符将数组转换为方法参数:

system *%W[git rev-list HEAD...#{remote}/master --count]
Run Code Online (Sandbox Code Playgroud)