具有特定参数顺序的语法错误

Tyl*_*hko 0 ruby syntax hash literals

使用此代码:

Sponsorship.includes(patient: :vaccinations, :backer)
Run Code Online (Sandbox Code Playgroud)

我得到syntax error, unexpected ')', expecting =>.但是当我像这样更改参数的顺序时:

Sponsorship.includes(:backer, patient: :vaccinations)
Run Code Online (Sandbox Code Playgroud)

错误消失了.为什么语法错误取决于参数的顺序?

Dav*_*ton 5

因为哈希参数需要是最后一个参数,如果你依赖Ruby语法糖来避免写{}自己.