34,333
edits
Changes
New page: In the Understanding Ruby Arrays we looked at the basics of arrays in Ruby. In this chapter we will look at arrays in more detail. == Combining Ruby Arrays == Arrays in Ruby can be c...
In the [[Understanding Ruby Arrays]] we looked at the basics of arrays in Ruby. In this chapter we will look at arrays in more detail.
== Combining Ruby Arrays ==
Arrays in Ruby can be concatenated using a number of different approaches. One option is to simply ''add' them together:
<pre>
days1 = ["Mon", "Tue", "Wed"]
days2 = ["Thu", "Fri", "Sat", "Sun"]
days = days1 + days2
=> ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
</pre>
Arrays can also be combined using the ''<<'' operator:
== Combining Ruby Arrays ==
Arrays in Ruby can be concatenated using a number of different approaches. One option is to simply ''add' them together:
<pre>
days1 = ["Mon", "Tue", "Wed"]
days2 = ["Thu", "Fri", "Sat", "Sun"]
days = days1 + days2
=> ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
</pre>
Arrays can also be combined using the ''<<'' operator: