Section 2.16. Implicit and Explicit Conversion

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"

The Ruby Way(c) Solutions and Techniques in Ruby Programming
The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)
ISBN: 0672328844
EAN: 2147483647
Year: 2004
Pages: 269
Authors: Hal Fulton

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: