To find the last character in a string in ruby, you can use the String#[]
method with -1
as the argument. This accesses the element at index -1
, which is the last character in the string.
main.rb79 chars4 lines
You can also use the String#slice
method with the same argument:
main.rb85 chars4 lines
Either of these methods will give you the last character in a ruby string.
gistlibby LogSnag