<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Man With Code &#187; arrays</title>
	<atom:link href="http://manwithcode.com/tag/arrays/feed/" rel="self" type="application/rss+xml" />
	<link>http://manwithcode.com</link>
	<description>Teaching You, One Tutorial at a Time</description>
	<lastBuildDate>Tue, 22 Feb 2011 23:40:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Programming With Ruby Episode 7, Arrays</title>
		<link>http://manwithcode.com/119/programming-with-ruby-episode-7-arrays/</link>
		<comments>http://manwithcode.com/119/programming-with-ruby-episode-7-arrays/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 06:19:31 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=119</guid>
		<description><![CDATA[Covered In This Episode: What Aarrays Are Array Creation Accessing Arrays Array Iteration Other Array Methods Transcript: Hello everybody and welcome to Programming With Ruby Episode 7, Arrays. I&#8217;m Tyler. And this video is brought to you by manwithcode.com In this episode I will be telling you what arrays are, how you can create an [...]]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/_jHM-3h-Bag&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/_jHM-3h-Bag&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p><strong>Covered In This Episode:</strong></p>
<ul>
<li>What Aarrays Are</li>
<li>Array Creation</li>
<li>Accessing Arrays</li>
<li>Array Iteration</li>
<li>Other Array Methods</li>
</ul>
<p><strong>Transcript:</strong></p>
<p>Hello everybody and welcome to Programming With Ruby Episode 7,<br />
Arrays. I&#8217;m Tyler. And this video is brought to you by manwithcode.com</p>
<p>In this episode I will be telling you what arrays are, how you can<br />
create an array in ruby. How to manipulate arrays by accessing them,<br />
iterating over them, and by showing you a few useful methods they<br />
have.</p>
<p>Lets get started!</p>
<p><strong>What are Arrays?</strong></p>
<p>Arrays are a type of variable. Think of an array as a list. This list<br />
can hold anything, names, numbers, objects, anything. Objects in the<br />
array have a number, depending on what place they are in the<br />
list.</p>
<p>Because computers start counting at 0, the first element in the<br />
array is 0, instead of one.</p>
<p><strong>Array Creation</strong></p>
<p>This is how a variable is defined in ruby:</p>
<pre class="brush: ruby; title: ; notranslate">
x = []
</pre>
<p>This is an empty array, if we wanted an array with something in it:</p>
<pre class="brush: ruby; title: ; notranslate">
todo_list = [&quot;Cut Grass&quot;, &quot;Buy Food&quot;, &quot;Fix Tom's Computer&quot;]
</pre>
<p>Each bracket represents the start and the end of the array,<br />
respectively. Each item in an array is separated by a comma.</p>
<p><strong>Accessing Arrays</strong></p>
<p>Now that you have created an array, how do you go about accessing each<br />
item?</p>
<p>I told you earlier that each item had a number, so to access the first<br />
item in the array you would do:</p>
<pre class="brush: ruby; title: ; notranslate">
todo_list[0] #=&gt; &quot;Cut Grass&quot;
</pre>
<p>You can also add items to an array in a similar way</p>
<pre class="brush: ruby; title: ; notranslate">
todo_list[3] = &quot;Go Skydiving&quot;
</pre>
<p>Another way to add items is to use +=, which you may recognize from<br />
previous tutorials</p>
<pre class="brush: ruby; title: ; notranslate">
todo_list += [&quot;Eat Sandwich&quot;]
</pre>
<p>Don&#8217;t forget that if you use += that the item your adding has to be<br />
between brackets</p>
<p>You can also use ranges to access elements in the array. ranges are<br />
used in a similar way that you normally access arrays, except ranges<br />
look like this:</p>
<pre class="brush: ruby; title: ; notranslate">
todo_list[0..2] #=&gt; [&quot;Cut Grass&quot;, &quot;Buy Food&quot;, &quot;Fix Tom's Computer&quot;]
</pre>
<p>The 0 is the start number and the 2 is the end number. you can also<br />
use -1, which is the end of the array:</p>
<pre class="brush: ruby; title: ; notranslate">
todo_list[3..-1] #=&gt; [&quot;Go Skydiving&quot;, &quot;Eat Sandwich&quot;]
</pre>
<p><strong>Array Iteration</strong></p>
<p>If you want to loop over each element of an array you use the each<br />
method:</p>
<pre class="brush: ruby; title: ; notranslate">
numbers = [1, 2, 3, 4]
numbers.each do |number|
puts number * 2
end
#=&gt; 2 4 6 8
</pre>
<p>You can do the same thing, but turn the output into an array with the<br />
collect method:</p>
<pre class="brush: ruby; title: ; notranslate">
numbers = [1, 2, 3, 4]
numbers.each do |number|
number * 2
end
#=&gt; [2,4,6,8]
</pre>
<p><strong>Other Array Methods</strong></p>
<p>Now I&#8217;m going to show you some useful methods arrays have!</p>
<p><em>empty?</em> tells you if an array is empty<br />
<em>sort</em> sorts the array (alphabetically)<br />
<em>reverse</em> reverses the array<br />
<em>delete</em> deletes a specified item from the array<br />
<em>delete_at</em> deletes whatever is at that index in the array<br />
<em>find</em> finds an item with the specified value<br />
<em>inspect</em> returns the way an array looks in code, instead of its values, this is useful for puts my_array.inspect<br />
<em>length</em> how long the array is</p>
<p>That&#8217;s it for today&#8217;s episode</p>
<p>Please don&#8217;t forget to donate, the link should be to the right of this video</p>
<p>If you have any questions or comments, leave a comment on this page or<br />
email me at tyler@manwithcode.com</p>
<p>Thanks for watching, bye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/119/programming-with-ruby-episode-7-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
	</channel>
</rss>

