我有以下代码:
def parse_package_url package, directory
branchget = package.split '@'
branch = branchget.length > 1 ? branchget[1] : false
siteget = branchget[0].split(':')
site = siteget.length > 1 ? siteget[0] : 'gitlab'
repoget = (siteget.length > 1 ? siteget[1] : siteget[0]).split '/'
packagename = repoget[1]
packageuser = repoget[0]
path = "#{directory}/#{packagename}"
{
:branch => branch,
:site => site,
:name => packagename,
:user => packageuser
:path => path,
:repo => repoget.join('/')
}
end
运行此代码后,我收到以下错误:
syntax error, unexpected tSYMBEG, expecting '}' (SyntaxError)
:path => path,
^
syntax error, unexpected tASSOC, expecting tCOLON2 or '[' or '.'
:repo => repoget.join('/')
syntax error, unexpected '}', expecting keyword_end
我无法在此代码中发现我的语法错误,如果有人能够指出它,我将不胜感激。
答案 0 :(得分:3)
您在:user => packageuser
之后错过了导致语法错误的逗号。有了这些错误,多年的凝视让我知道这个问题通常比Ruby给你的行数高出一行。