Ruby Quirks - String#[]
Ruby String class has []
operator that allows us to get a substring
for a given string. For example:
However, if you pass a single index to the []
operator, the response
is not something you would expect. For example:
While we are in the topic of characters and their ASCII representation,
Ruby provides a ?
operator to evaluate the ASCII representation of a
string. For example:
This quirk can be seen in Ruby 1.8.7 and earlier versions of Ruby. However, from 1.9.1, the behavior is as expected. For example, in 1.9.1 and beyond:
blog comments powered by Disqus