0

我正在尝试做:

the_tag= line[2..5]
rec_id_line = (line[2]=='@')? true : false

new_contents,new_to_close= 
  rec_id_line? open_id_tag(indent,line) : open_tag(indent,the_tag,last_field)

这两种方法都返回两个值(顺便说一句,我在这里重构)

即对于这两个变量,我要么想调用,open_id_tag(2 params)否则open_tag(3 params)取决于真/假 rec_id_line 值。

4

1 回答 1

2

你只需要在rec_id_lineand之间放一个空格?

new_contents, new_to_close = rec_id_line ? open_id_tag(indent, line) : open_tag(indent, the_tag, last_field)

此外line[2]=='@',可能会返回一个布尔值,因此可以简化您的第二行:

rec_id_line = (line[2] == '@')

或者结合这两行:

new_contents, new_to_close = (line[2] == '@') ? open_id_tag(indent, line) : open_tag(indent, the_tag, last_field)
于 2013-06-29T18:27:00.877 回答