1. Conclusion </ b>
2. How to code </ b>
3. Development environment </ b>
Use gets.chomp, length </ b> methods !!
str = gets.chomp #---❶
str_length = str.length
puts('~' * (str_length + 2)) #---❷
puts('~'+str+'~') #---❸
puts('~' * (str_length + 2)) #---❷
If you do this, it will look like this:
❶: If you do not enter .chomp, it will be as follows. A line break is made and the last "~" on the second line is attached. ❷: The length of the character entered by the length method is +2. The reason for +2 is to add the "~" in the upper left and the "~" in the upper right. ❸: "~" Is added to both ends of the entered character.
Mac catalina 10.15.4
Vscode
Ruby 2.6.5
Rails 6.0.3.3
Recommended Posts