How can I get Ruby to treat the index of a string as a character (rather than the ASCII code)?
- by user336777
I am checking to see if the last character in a directory path is a '/'. How do you get ruby to treat the specific index of a string as a character rather than the associated ASCII code?
For example the following always returns false:
dir[dir.length - 1] == '/'
This is because dir[dir.length - 1] returns the ASCII code 47 (rather than '/').
Any thoughts on how to interpret 47 as '/'? Or is there a completely different way to handle this in the first place?
thanks.