Ruby-如何基于另一个布尔变量分配多个变量?

Ruby-如何基于另一个布尔变量分配多个变量?,ruby,Ruby,我正在努力做到: 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) 这两个方法都返回两个值(顺便说一句,我正在重构) i、 e.对于这两个变量,我想调用open\u id\u-tag(2个参数)否则open\

我正在努力做到:

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)
这两个方法都返回两个值(顺便说一句,我正在重构)


i、 e.对于这两个变量,我想调用
open\u id\u-tag(2个参数)
否则
open\u-tag(3个参数)
取决于真/假rec\u-id\u-line值。

您只需在
rec\u-id\u-line
之间放置一个空格即可:

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)