Home > Articles > Programming > Ruby

📄 Contents

  • Print
  • + Share This
This chapter is from the book

2.15 Converting Between Characters and ASCII Codes

In Ruby, a character is already an integer. This behavior is slated to change in 2.0 or perhaps sooner. In future versions of Ruby, the current plan is to store a character as a one-character string.

str = "Martin"
print str[0]        # 77

If a Fixnum is appended directly onto a string, it is converted to a character:

str2 = str << 111   # "Martino"
  • + Share This
  • 🔖 Save To Your Account