从方法内部调用命令行参数?

时间:2014-04-21 15:21:21

标签: ruby command-line-arguments

我遇到了从方法内部调用命令行参数的问题。

这是我脚本的片段。在前几个操作中,参数作为方法选项/参数传递,参数值被正确映射。在最后一个操作中,在方法内部调用参数,参数作为文本传递。我是否缺少从方法内部调用变量的特定语法?

# sets the command-line argument as a global variable
evidence_name = ARGV[0]

# The argument value (evidence_name)is successfully called below as an
# option/parameter
evidence = processor.newEvidenceContainer(evidence_name)
evidence.custom_metadata = { 'Barcode' => evidence_name }
evidence.addFile(evidence_path)
evidence.save

# Instead of calling the argument value (evidence_name), the method is
# reading evidence_name as text. So the script is searching for
# "evidence_name" and not the value that I specified from the command-line
# at runtime.
all_files = current_case.search('evidence-metadata:evidence_name AND contains-text:1')

1 个答案:

答案 0 :(得分:3)

是的,你缺少字符串插值。

"evidence-metadata:#{evidence_name} AND contains-text:1"