0

I am trying to do:

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)

Those two methods both return two values (btw I'm refactoring here)

i.e. for the two variables, I either want to call open_id_tag(2 params) otherwise open_tag(3 params) depending on the true/false rec_id_line value.

1 Answer 1

2

You just have to put a space between rec_id_line and ?:

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

Furthermore line[2]=='@' probably returns a boolean value so can simplify your second line:

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

Or combine both lines:

new_contents, new_to_close = (line[2] == '@') ? open_id_tag(indent, line) : open_tag(indent, the_tag, last_field)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.