To get the last characters of a string in Ruby, use the following instructions. If the string is shorter than the selected number of characters, the entire string is returned.
a = '12345' b = a[-3..-1] || a puts b
Returns
345
Knowledge Base for IT Professionals, Teachers and Astronauts
To get the last characters of a string in Ruby, use the following instructions. If the string is shorter than the selected number of characters, the entire string is returned.
a = '12345' b = a[-3..-1] || a puts b
Returns
345