34,333
edits
Changes
no edit summary
== Converting a Ruby String to an Array ==
Strings can be converted to arrays using a combination of the ''split'' method and some regular expressions. The ''split'' methods method serves to break up the string into distinct parts which that can be placed into array element. The regular expression tells ''split'' what to use as the break point during the conversion process.
We can start by converting an entire string into an array with just one element (i.e . the entire string):
<pre>
</pre>
This has created an array object called myArray. Unfortunately this isn't much use to us because we wanted each character in our string to be placed in a an individual array element. To do this we need to specify a regular expression. In this case we need to use the regular expression which represents the point between two characters (//) and pass it through as an argument to the ''split'' method:
<pre>