ChefRuby Last characters of a string in Ruby By Laszlo Pinter October 13, 2016 1 Min Read 0 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 Tags: ChefRuby