Write a Ruby program to create a new string where "if" is added to the front of a given string. If the string already begins with "if", return the string unchanged.
Ruby Code:
def if_string(str) str[0, 3] == "if " ? str : "if " << str end print if_string("if else"),"\n" print if_string("else"),"\n"
if else if else
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Ruby Code: