<?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; Videos</title>
	<atom:link href="http://manwithcode.com/category/videos/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>Apology</title>
		<link>http://manwithcode.com/371/apology/</link>
		<comments>http://manwithcode.com/371/apology/#comments</comments>
		<pubDate>Tue, 11 May 2010 03:17:22 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[apology]]></category>
		<category><![CDATA[sorry]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=371</guid>
		<description><![CDATA[Covered In This Episode I&#8217;m sorry Why I&#8217;ve been gone Making Games with Ruby update Thank you donators!]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/xNg9OkphKGY&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/xNg9OkphKGY&#038;hl=en&#038;fs=1" 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>I&#8217;m sorry</li>
<li>Why I&#8217;ve been gone</li>
<li>Making Games with Ruby update</li>
<li>Thank you donators!</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/371/apology/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Making Games with Ruby Ep. 3 &#8211; Basics</title>
		<link>http://manwithcode.com/322/making-games-with-ruby-ep-3-basics/</link>
		<comments>http://manwithcode.com/322/making-games-with-ruby-ep-3-basics/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 23:58:06 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Making Games With Ruby]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[basics window games rubygame ruby]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=322</guid>
		<description><![CDATA[Covered In This Episode: Creating a Window Basic Event Handling Transcript: Hello Everybody and welcome to making games with Ruby episode 3, Basics. I&#8217;m Tyler and these videos are brought to you by manwithcode.com. Today we&#8217;re just going to be talking about the very basics of game creation, just getting a window on the screen. [...]]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/rcsNp8deJVs&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/rcsNp8deJVs&#038;hl=en&#038;fs=1" 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>Creating a Window</li>
<li>Basic Event Handling</li>
</ul>
<p><strong>Transcript:</strong></p>
<p>Hello Everybody and welcome to making games with Ruby episode 3, Basics. I&#8217;m Tyler and these videos are brought to you by manwithcode.com.</p>
<p>Today we&#8217;re just going to be talking about the very basics of game creation, just getting a window on the screen. The code for this episode is on manwithcode.com, if you&#8217;re not there already. <a title="Making Games with Ruby Episode 3 - Basics" href="http://manwithcode.com/322/making-games-with-ruby-ep-3-basics">http://manwithcode.com/322/making-games-with-ruby-ep-3-basics</a></p>
<p>Lets get started!</p>
<p>We&#8217;re going to start by requiring in the libraries we need, which for now is only rubygems and rubygame:</p>
<pre class="brush: ruby; title: ; notranslate">
require 'rubygems'
require 'rubygame'
</pre>
<p>Then we&#8217;re going to create the main Game class, and stub out all the methods in it:</p>
<pre class="brush: ruby; title: ; notranslate">
class Game
	def initialize
	end

	def run!
	end

	def update
	end

	def draw
	end
end
</pre>
<p>And after that we&#8217;re going to add the code to run the game:</p>
<pre class="brush: ruby; title: ; notranslate">
g = Game.new
g.run!
</pre>
<p>So far this is just some very basic structure, nothing really happens yet. I&#8217;m going to run the code just to double check we have no syntax errors&#8230;</p>
<p>The first thing we&#8217;re going to do is initialize everything we&#8217;ll need:</p>
<pre class="brush: ruby; title: ; notranslate">
def initialize
	@screen = Rubygame::Screen.new [640, 480], 0, [Rubygame::HWSURFACE, Rubygame::DOUBLEBUF]
	@screen.title = &quot;Pong&quot;

	@queue = Rubygame::EventQueue.new
	@clock = Rubygame::Clock.new
	@clock.target_framerate = 60
end
</pre>
<p>Some of this is self explaitory, but let&#8217;s break it down. The first line of <code>initialize</code> creates the window for our game, Rubygame calls this a Screen. The first argument <code>[640, 480]</code> is the size of the screen, the second is the screen depth (you don&#8217;t need to worry about this), the last one is a list of flags we pass to rubygame. HWSURFACE means we want it to be accelerated on the graphics card if available, and DOUBLEBUF means we want the screen to be double buffered. Double buffering is a way of drawing to the screen. I won&#8217;t go into too much detail right now to explain double buffering, but I will in a later episode.</p>
<p>The second line has an obvious purpose, it sets the title at the top of the screen to Pong</p>
<p>The fifth line is setup so we can handle events, I&#8217;ll talk more about this later.</p>
<p>The last two lines are the setup so we can limit the framerate to 60 frames per second. The frame rate is how many times the screen is drawn every second (we&#8217;ll be doing our drawing in the <code>Game#draw</code> method). If we let this go unchecked, our game will run as fast as possible which isn&#8217;t desireable since top speed will be different on different computers, and depending on what the game is doing at a particular moment in time. I think 60 is a good number, but we can easily change it later if we want.</p>
<p>Next we&#8217;re going to setup the main game loop:</p>
<pre class="brush: ruby; title: ; notranslate">
def run!
	loop do
		update
		draw
		@clock.tick
	end
end
</pre>
<p>This loops indefinately until we decide in a different part of the code to end the game. <code>@clock.tick</code> is what allows us to limit our framerate. You can now run the game, it should just be a black screen. You can see the title at the top, like we set in the initialize function.</p>
<p>But if you try to close the window&#8230; Nothing happens!!! To close it try pressing CTRL+C in the command prompt window, or you may have to go to the task manager and kill it from there. To fix this problem, we need to talk about the event queue.</p>
<p>We&#8217;re going to start by defining the <code>update</code> method:</p>
<pre class="brush: ruby; title: ; notranslate">
def update
	@queue.each do |ev|
		case ev
			when Rubygame::QuitEvent
				Rubygame.quit
				exit
		end
	end
end
</pre>
<p>Whenever the user gives us some input, presses a key, moves the mouse, etc. the Rubygame adds an event for this input onto the queue. We handle these events in our update method.</p>
<p><code>@queue.each</code> loops over each event, and we have a case statement that handles the event depending on the type. For closing the window, the event type is <code>Rubygame::QuitEvent</code>, which is generated whenever the user presses the close window button or ALT+F4.</p>
<p>Now if you run the game, the window should appear and you should be able to close it now! Yay!</p>
<p>This is the final source listing for this episode:</p>
<pre class="brush: ruby; title: ; notranslate">
require 'rubygems'
require 'rubygame'

class Game
	def initialize
		@screen = Rubygame::Screen.new [640, 480], 0, [Rubygame::HWSURFACE, Rubygame::DOUBLEBUF]
		@screen.title = &amp;quot;Pong&amp;quot;

		@queue = Rubygame::EventQueue.new
		@clock = Rubygame::Clock.new
		@clock.target_framerate = 60
	end

	def run!
		loop do
			update
			draw
			@clock.tick
		end
	end

	def update
		@queue.each do |ev|
			case ev
				when Rubygame::QuitEvent
					Rubygame.quit
					exit
			end
		end
	end

	def draw
	end
end

g = Game.new
g.run!
</pre>
<p>This brings us to the end of the episode.</p>
<p>If you have any questions, comments, or suggestions, leave a comment on this page or email me at tyler@manwithcode.com.</p>
<p>Thank you very much for watching! Goodbye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/322/making-games-with-ruby-ep-3-basics/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<series:name><![CDATA[Making Games With Ruby]]></series:name>
	</item>
		<item>
		<title>Making Games with Ruby Ep. 2 &#8211; Setup</title>
		<link>http://manwithcode.com/310/making-games-with-ruby-ep-2-setup/</link>
		<comments>http://manwithcode.com/310/making-games-with-ruby-ep-2-setup/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 00:06:26 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Making Games With Ruby]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[setup rubygame windows mac linux]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=310</guid>
		<description><![CDATA[Windows: Mac: Linux: Links: Rubygame Installation guides Rubygame windows dependencies Covered in This Episode: How to get set up for this series on Windows, Mac, and Linux]]></description>
			<content:encoded><![CDATA[<p><strong>Windows:</strong></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/zJgyefzctRg&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/zJgyefzctRg&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<pre class="brush: plain; title: ; notranslate">
gem install rubygame
</pre>
<p><strong>Mac:</strong></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/URGqLBfcI5A&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/URGqLBfcI5A&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><strong>Linux:</strong></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/aq0LGlMrQgM&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/aq0LGlMrQgM&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<pre class="brush: plain; title: ; notranslate">
sudo apt-get install -y libsdl1.2debian libsdl1.2-dev libsdl-image1.2 libsdl-image1.2-dev libsdl-ttf2.0-0 libsdl-ttf2.0-dev libsdl-mixer1.2 libsdl-mixer1.2-dev libsdl-gfx1.2-4 libsdl-gfx1.2-dev

sudo gem install rubygame
</pre>
<p><strong>Links:</strong></p>
<ul>
<li><a title="Rubygame installation guides" href="http://rubygame.org/wiki/Installation_Instructions">Rubygame Installation guides</a></li>
<li><a title="Rubygame windows dependancies" href="http://manwithcode.com/wp-content/uploads/2009/11/rubygame-deps.zip">Rubygame windows dependencies</a></li>
</ul>
<p><strong>Covered in This Episode:</strong></p>
<ul>
<li>How to get set up for this series on Windows, Mac, and Linux</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/310/making-games-with-ruby-ep-2-setup/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<series:name><![CDATA[Making Games With Ruby]]></series:name>
	</item>
		<item>
		<title>Making Games With Ruby Ep. 1 &#8211; Intro</title>
		<link>http://manwithcode.com/299/making-games-with-ruby-ep-1-intro/</link>
		<comments>http://manwithcode.com/299/making-games-with-ruby-ep-1-intro/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 22:02:31 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Making Games With Ruby]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[intro]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=299</guid>
		<description><![CDATA[Links: Programming with Ruby Video Tutorials Covered In This Episode: What you&#8217;ll learn What we&#8217;re using What I&#8217;m assuming about you Why I&#8217;m teaching this Transcript: Hello Everybody, and Welcome to the first episode of Making Games With Ruby! I&#8217;m Tyler, and this video is brought to you by manwithcode.com In this episode I&#8217;ll be [...]]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/QnXPUEXKrzg&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/QnXPUEXKrzg&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p><strong>Links:</strong></p>
<ul>
<li><a title="Programming With Ruby - Man With Code" href="http://manwithcode.com/ruby-programming-tutorials/">Programming with Ruby Video Tutorials</a></li>
</ul>
<p><strong>Covered In This Episode:</strong></p>
<ul>
<li>What you&#8217;ll learn</li>
<li>What we&#8217;re using</li>
<li>What I&#8217;m assuming about you</li>
<li>Why I&#8217;m teaching this</li>
</ul>
<p><strong>Transcript:</strong></p>
<p>Hello Everybody, and Welcome to the first episode of Making Games With Ruby! I&#8217;m Tyler, and this video is brought to you by manwithcode.com</p>
<p>In this episode I&#8217;ll be covering what you will be learning in this series, what we&#8217;re using to develop our games, what I&#8217;m assuming about you, and why I&#8217;m teaching you.</p>
<p><strong>What you&#8217;ll learn</strong></p>
<p>If you couldn&#8217;t tell by the title, you&#8217;re going to learn how to make games using the Ruby programming language. More specifically I&#8217;m going to teach you how to make Pong. Though Pong may sound a little simplistic, and I&#8217;m not claiming it isn&#8217;t, learning how to make Pong will teach you almost everything you&#8217;ll need to know to make any game, with out getting bogged down in game specific details.<strong></strong></p>
<p><strong>What we&#8217;re using</strong></p>
<p>Of course we&#8217;re using the Ruby programming language. To create games, we&#8217;ll have the help of the Rubygame library, which is many things including a wrapper around SDL, and a nice framework for developing games.</p>
<p>In the creation of this series I will be using Ruby 1.8.7-p174, and Rubygame 2.6.2. Theoretically The code in this series should run on Ruby 1.8.whatever and Rubygame 2.whatever, no promises though, since languages and libraries change.</p>
<p>And if you want to know about my environment, I&#8217;ll be running Ubuntu 9.10 as my Operating System, and using Gedit as my text editor. You can write and run the code on any platform you wish, but this is what I prefer.</p>
<p><strong>What I&#8217;m assuming about you</strong></p>
<p>So I don&#8217;t have to explain every line of code to you, I&#8217;m going to be assuming that you already know the Ruby programming language. If you don&#8217;t there are many books available, as well as my own video series Programming With Ruby at http://manwithcode.com/ruby-programming-tutorials/</p>
<p>Just reading one book, or watching my video series probably isn&#8217;t enough. I&#8217;ll be easier if you have used Ruby for a while, and are comfortable with it. This isn&#8217;t<br />
a requirement, but it would help make things easier on yourself.</p>
<p><strong>Why I&#8217;m teaching this</strong></p>
<p>There are many reasons why, but I&#8217;ll talk about the most important few:</p>
<p>1) I love making games.<br />
2) I love teaching.<br />
3) Teaching teaches me something. &#8211; When you actually sit down and think about what you do, things become more concrete, and you know why you do what you do, or even see bad habits that you need to correct<br />
4) I&#8217;m trying to make money &#8211; Yep, I&#8217;m not going to try and hide this. Some of the videos in this series will be put up for sale, you&#8217;ll be able to see them as I put out more videos.</p>
<p>Thank you very much for watching! I&#8217;ll see you in the next video.</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/299/making-games-with-ruby-ep-1-intro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Making Games With Ruby]]></series:name>
	</item>
		<item>
		<title>Programming With Ruby, Feedback</title>
		<link>http://manwithcode.com/233/programming-with-ruby-feedback/</link>
		<comments>http://manwithcode.com/233/programming-with-ruby-feedback/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 09:06:29 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[feedback]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=233</guid>
		<description><![CDATA[Links: Donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&#38;hosted_button_id=4222118 Submit This Link: http://manwithcode.com/ruby-programming-tutorials/ Vote: http://manwithcode.com/tutorials-under-consideration/ Leave Feedback Here: http://manwithcode.com/235/leave-feedback-here-programming-with-ruby-feedback/ Covered In This Episode: $1000 or 1000 comments Submit to Social Media Transcript: Hello Everybody and welcome to Programming With Ruby, Feedback. I&#8217;m Tyler, and this video is brought to you by manwithcode.com. In this video I&#8217;m going to be going over [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/Dil0aCdk898&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/Dil0aCdk898&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><strong>Links:</strong></p>
<ul>
<li>Donate:<a title="Donate to Man With Code" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=4222118"> https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=4222118</a></li>
<li>Submit This Link: <a title="All Programming With Ruby Episodes" href="http://manwithcode.com/ruby-programming-tutorials/">http://manwithcode.com/ruby-programming-tutorials/</a></li>
<li>Vote: <a title="Vote for the next series" href="http://manwithcode.com/tutorials-under-consideration/">http://manwithcode.com/tutorials-under-consideration/</a></li>
<li>Leave Feedback Here: <a title="Feedback for Programming With Ruby series" href="http://manwithcode.com/235/leave-feedback-here-programming-with-ruby-feedback/">http://manwithcode.com/235/leave-feedback-here-programming-with-ruby-feedback/</a></li>
</ul>
<p><strong>Covered In This Episode:</strong></p>
<ul>
<li>$1000 or 1000 comments</li>
<li>Submit to Social Media</li>
</ul>
<p><strong>Transcript:</strong></p>
<p>Hello Everybody and welcome to Programming With Ruby, Feedback. I&#8217;m<br />
Tyler, and this video is brought to you by manwithcode.com.</p>
<p>In this video I&#8217;m going to be going over what needs to happen for me<br />
to produce the next series of video tutorials.</p>
<p>All links I mention will be in the video description</p>
<p>First things first, if you head on over to<br />
<a title="Vote for the next series" href="http://manwithcode.com/tutorials-under-consideration/">http://manwithcode.com/tutorials-under-consideration/</a></p>
<p>You can vote on what the next video series will be.</p>
<p>So if you vote I will know what YOU want, now you need to know what I<br />
want for the next series to happen.</p>
<p>I&#8217;ve had well over 1,000 unique viewers of this video series, so I<br />
need you viewers to donate a total of $1000 before I make the next<br />
series. This may seem like a high amount, but if only 200 people<br />
donate $5, that is a thousand dollars.</p>
<p><a title="Donate to Man With Code" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=4222118"> </a>Donate:<a title="Donate to Man With Code" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=4222118"> https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=4222118</a></p>
<p>Now, what if you don&#8217;t have the money to donate? I will be making a<br />
post on manwithcode.com named Ruby Video Tutorial Feedback, if 1000<br />
people leave feedback (i.e. What they liked, what they didn&#8217;t like).</p>
<p>So whatever comes first, 1000 comments or $1000 will cause me to start<br />
the next video series.</p>
<p>For updates on how close we are to each goal, I will be on twitter at<br />
the account tylerjchurch and with the tag #manwithcode.</p>
<p>Now what if you can&#8217;t donate money, and you can&#8217;t write me feedback?<br />
Then there is something else you can do!<br />
<a title="All Programming With Ruby Episodes" href="http://manwithcode.com/ruby-programming-tutorials/">http://manwithcode.com/ruby-programming-tutorials/</a></p>
<ul>
<li> Tweet on Twitter</li>
<li> Give a thumbs up on StumbleUpon</li>
<li> Submit to Digg</li>
<li> Submit to Reddit</li>
<li> Bookmark on delicious</li>
<li> Blog about</li>
<li> or you can just Tell a friend</li>
</ul>
<p>And hopefully one of those people who come along will donate or leave<br />
feedback.</p>
<p>So don&#8217;t forget to donate, leave feedback, or submit the provided link<br />
to social media!</p>
<p>Thanks for watching, bye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/233/programming-with-ruby-feedback/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<item>
		<title>Programming With Ruby Episode 18, Out Into The World</title>
		<link>http://manwithcode.com/227/programming-with-ruby-episode-18-out-into-the-world/</link>
		<comments>http://manwithcode.com/227/programming-with-ruby-episode-18-out-into-the-world/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 09:00:06 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[libraries]]></category>
		<category><![CDATA[moving on]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=227</guid>
		<description><![CDATA[Covered In This Episode: Where to go from here Books Libraries A few other things&#8230; Transcript: Hello Everybody and welcome to Programming With Ruby Episode 18, Out Into The World. I&#8217;m Tyler and this video is brought to you by manwithcode.com. In this episode I will be telling you where to go from here, now [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/8jHsE27voRQ&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/8jHsE27voRQ&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><strong>Covered In This Episode:</strong></p>
<ul>
<li>Where to go from here</li>
<li>Books</li>
<li>Libraries</li>
<li>A few other things&#8230;</li>
</ul>
<p><strong>Transcript:</strong></p>
<p>Hello Everybody and welcome to Programming With Ruby Episode 18, Out<br />
Into The World. I&#8217;m Tyler and this video is brought to you by<br />
manwithcode.com.</p>
<p>In this episode I will be telling you where to go from here, now that<br />
you know the basics of Ruby. I&#8217;ll show you some books, some common<br />
libraries. And I&#8217;ll go over a few more things.</p>
<p><strong>Where to go from here </strong></p>
<p>Now that this series is almost done, you may be wondering what you<br />
should do. First, I recommend you start writing your own<br />
programs. Find something you would like to write and just try writing<br />
it.</p>
<p>You may also want to read a few other resources like books and online<br />
tutorials about Ruby for things I didn&#8217;t cover and to reinforce what<br />
you have learned.</p>
<p><strong>For books I would recommend:</strong></p>
<ul>
<li>Beginning Ruby, From Novice to Professional</li>
<li>The Ruby Programming Language</li>
</ul>
<p>If you are trying to make something, but can&#8217;t do it with Ruby alone,<br />
here are some libraries in a few common areas. I won&#8217;t be providing<br />
links, but a quick Google search will find them for you.</p>
<p><strong>Web Development</strong></p>
<ul>
<li>Ruby on Rails</li>
<li>Sinatra</li>
<li>Merb</li>
</ul>
<p><strong>Game Development</strong></p>
<ul>
<li>Rubygame</li>
<li>rubysdl</li>
<li>Gosu</li>
</ul>
<p><strong>Testing</strong></p>
<ul>
<li>rspec</li>
<li>cucumber</li>
</ul>
<p><strong>Images</strong></p>
<ul>
<li>RMagic</li>
</ul>
<p><strong>GUI Toolkits</strong></p>
<ul>
<li>Ruby-WxWidgets</li>
<li>Ruby-GNOME2</li>
<li>Shoes</li>
</ul>
<p>If you need a library for something I didn&#8217;t cover, you can check<br />
Ruby&#8217;s documentation at ruby-doc.org, you can try and find a project<br />
by searching at rubyforge.org and github.com. If all else fails, just<br />
Google it.</p>
<p>This is actually the end of the episode, but though this video is<br />
purported as the end of the series, there is going to be at least one<br />
more video, so stay tuned.</p>
<p>If you&#8217;ve liked this series, please donate!</p>
<p>If you have and questions, comments, or suggestions about this series<br />
or Man With Code, you can leave a comment on this page or email me at<br />
tyler@manwithcode.com</p>
<p>Thanks for watching, goodbye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/227/programming-with-ruby-episode-18-out-into-the-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<item>
		<title>Programming With Ruby Episode 17, Getting Advanced</title>
		<link>http://manwithcode.com/222/programming-with-ruby-episode-17-getting-advanced/</link>
		<comments>http://manwithcode.com/222/programming-with-ruby-episode-17-getting-advanced/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 08:56:27 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[advanced]]></category>
		<category><![CDATA[bindings]]></category>
		<category><![CDATA[eval]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[symbols]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=222</guid>
		<description><![CDATA[Covered In This Episode: Symbols eval Bindings Running Other Programs Safe Levels Transcript: Hello Everybody and welcome to Programming With Ruby Episode 17, Getting Advanced. I&#8217;m Tyler, and this video is brought to you by manwithcode.com. By now, you know a large amount about Ruby, so in this episode we will be going over some [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/0dnHp7Yhbuo&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/0dnHp7Yhbuo&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><strong>Covered In This Episode:</strong></p>
<ul>
<li>Symbols</li>
<li>eval</li>
<li>Bindings</li>
<li>Running Other Programs</li>
<li>Safe Levels</li>
</ul>
<p><strong>Transcript:</strong></p>
<p>Hello Everybody and welcome to Programming With Ruby Episode 17,<br />
Getting Advanced. I&#8217;m Tyler, and this video is brought to you by<br />
manwithcode.com.</p>
<p>By now, you know a large amount about Ruby, so in this episode we will<br />
be going over some advanced features that Ruby has.</p>
<p>More specifically I will be teaching you what Symbols are, and when to<br />
use them. I will be showing you how to use eval, and how to use<br />
bindings with eval. You will learn how to run other programs from<br />
Ruby. Finally I will show you what safe levels are.</p>
<p>Lets get started!</p>
<p><strong>Symbols</strong></p>
<p>Symbols are a type of variable that are very much like strings, but<br />
more lightweight. Symbols look like this:</p>
<pre class="brush: ruby; title: ; notranslate">
:variable
</pre>
<p>Symbols can&#8217;t be manipulated like strings can, which seems like a huge<br />
drawback, but they do have a couple benefits.</p>
<p>Each time you use a string, to say access a hash. Ruby creates an<br />
instance of that string. Where if you use a symbol, it is only ever<br />
instanced once. Meaning that the use of symbols will take up less<br />
memory than strings will, if you are, say accessing a hash many times.</p>
<p>Symbols are also slightly easier to type since the colon is on the<br />
home row on US keyboards.</p>
<p><strong>eval</strong></p>
<p>eval is a way of running Ruby code that is contained in a string. For<br />
example, lets say you have a string that looks like this:</p>
<pre class="brush: ruby; title: ; notranslate">
&quot;puts 'Hello World'&quot;
</pre>
<p>It is just a simple string, so it does nothing. But, if you use the<br />
method eval on that string it will execute the code inside. So this<br />
will print Hello World! on to the screen:</p>
<pre class="brush: ruby; title: ; notranslate">
eval &quot;puts 'Hello World!'&quot;
</pre>
<p>This isn&#8217;t always useful, but you can use it if you want your users to<br />
be able to enter Ruby code into your program.</p>
<p>You can also pass bindings to eval. So if we had this method</p>
<pre class="brush: ruby; title: ; notranslate">
def my_method my_binding
    eval &quot;puts x&quot;, my_binding
end

x = 5
my_method binding
</pre>
<p>This outputs:</p>
<pre class="brush: plain; title: ; notranslate">
5
</pre>
<p>Some of you may notice that the variable x isn&#8217;t defined in the method <code>my_method</code>. By using the binding method, we can make variable scopes portable!</p>
<p><strong>Running Other Programs</strong></p>
<p>There comes a time when you will want to be able to run a program from<br />
Ruby, maybe you want to automate something, or simply get the output<br />
from an external program.</p>
<p>There are a few ways of doing this.</p>
<p>The first is with the method exec, which runs an external programs,<br />
and quits the Ruby script at the same time:</p>
<pre class="brush: ruby; title: ; notranslate">
exec('ls') # dir on windows
# Program never gets here
</pre>
<p>There is also system, which does the same thing, but doesn&#8217;t quit the<br />
Ruby script, and returns true or false if the program was successful:</p>
<pre class="brush: ruby; title: ; notranslate">
system('ls') # dir on windows
# we do get this far
</pre>
<p>Finally we have the &#8220;back-tick&#8221; `. Which looks like a sideways single<br />
quote. On my keyboard it is above the tab key. You surround your<br />
command in the back-ticks, like you would for a sting. Unlike the other<br />
two methods of running a program, this method also returns the output<br />
of the program you run.</p>
<pre class="brush: ruby; title: ; notranslate">
variable = `ls`
</pre>
<p><strong>Safe Levels</strong></p>
<p>If you are running a Ruby interpreter online or in another environment<br />
where users can enter in and run Ruby code. They hold the ability to<br />
wreak havoc on your system.</p>
<p>The way to prevent this from happening is by using safe levels. Safe<br />
levels are a way of preventing the user from getting access to the<br />
file system, or changing any variables that the program has.</p>
<p>You set safe levels by setting the $SAFE variable. By default it is<br />
set to zero.</p>
<pre class="brush: ruby; title: ; notranslate">
$SAFE = 4
</pre>
<p>Ruby &#8220;taints&#8221; objects that could be dangerous.</p>
<p>There are five different safe levels.<br />
0 =&gt; The default, you can do anything<br />
1 =&gt; Can&#8217;t use environment variable, eval, load, require, and more.<br />
2 =&gt; Same as above and also can&#8217;t use files<br />
3 =&gt; All objects created are tainted, can&#8217;t be untainted<br />
4 =&gt; You can do almost nothing&#8230; Can&#8217;t modify the untainted, can&#8217;t<br />
use exit. Basically completely safe and sand-boxed.</p>
<p>That brings us to the end of the episode. If you liked these videos,<br />
please donate. It costs me in both money and time to make them.</p>
<p>If you have any questions, comments, or suggestions please don&#8217;t<br />
hesitate to leave a comment on this page or email me at<br />
tyler@manwithcode.com</p>
<p>Thanks for watching, goodbye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/222/programming-with-ruby-episode-17-getting-advanced/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<item>
		<title>Programming With Ruby Episode 16, Benchmarking</title>
		<link>http://manwithcode.com/216/programming-with-ruby-episode-16-benchmarking/</link>
		<comments>http://manwithcode.com/216/programming-with-ruby-episode-16-benchmarking/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 08:31:11 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[benchmarking]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=216</guid>
		<description><![CDATA[Covered In This Episode: What is benchmarking? Benchmarking Profiling Transcript: Hello Everybody and welcome to Programming With Ruby Episode 16, Benchmarking. I&#8217;m Tyler and this video is brought to you by manwithcode.com. In this episode I will tell you what benchmarking is. You will learn how to preform benchmarking tests on some of your code. [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/dsa2RLZQoJY&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/dsa2RLZQoJY&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><strong>Covered In This Episode:</strong></p>
<ul>
<li>What is benchmarking?</li>
<li>Benchmarking</li>
<li>Profiling</li>
</ul>
<p><strong>Transcript:</strong></p>
<p>Hello Everybody and welcome to Programming With Ruby Episode 16,<br />
Benchmarking. I&#8217;m Tyler and this video is brought to you by<br />
manwithcode.com.</p>
<p>In this episode I will tell you what benchmarking is. You will learn<br />
how to preform benchmarking tests on some of your code. And after that<br />
you will learn how to preform the more exhaustive benchmarking process<br />
called profiling.</p>
<p>This should be a very quick and easy episode, so lets get started!</p>
<p><strong>What is benchmarking?</strong></p>
<p>Basically benchmarking is measuring how fast your code runs. Whether<br />
that means your code as a whole or only parts of it. This can be<br />
useful so you can optimize your code to run faster, in the places it<br />
is running the slowest. Benchmarking is also commonly used to compare<br />
two different programs in the category of speed, which can be a<br />
selling point for many products.</p>
<p><strong>Benchmarking</strong></p>
<p>To get access to benchmarking make sure you put:</p>
<pre class="brush: ruby; title: ; notranslate">
require 'benchmark'
</pre>
<p>in your code.</p>
<p>The most simple form of benchmarking is Benchmark.measure:</p>
<pre class="brush: ruby; title: ; notranslate">
a = Benchmark.measure do
    1_000_000.times do |i|
        x = i
    end
end

puts a #=&gt; 0.400000   0.140000   0.540000 (  0.537934)
</pre>
<p>The last number is the actual time it took to run the test.</p>
<p>There is also Benchmark.bm, which is similar, but adds headings and<br />
allows you to do multiple tests.</p>
<pre class="brush: ruby; title: ; notranslate">
Benchmark.bm do |bm|
    bm.report('Test 1:') do
        1_000_000.times do
            x = 1
        end
    end
    bm.report('Test 2:') do
        1_000.times do
            x = &quot;Moo...&quot;
        end
    end
end

# Example Output:
#          user     system      total        real
# Test 1:  0.430000   0.120000   0.550000 (  0.563787)
# Test 2:  0.000000   0.000000   0.000000 (  0.000775)
</pre>
<p>Then there is Benchmark.bmbm, which is exactly the same as bm, but<br />
preforms a benchmark twice.</p>
<pre class="brush: plain; title: ; notranslate">
Example Benchmark.bmbm Output:
Rehearsal -------------------------------------------
Test 1:   0.370000   0.110000   0.480000 (  0.484865)
Test 2:   0.000000   0.000000   0.000000 (  0.000529)
---------------------------------- total: 0.480000sec

user     system      total        real
Test 1:   0.390000   0.090000   0.480000 (  0.477402)
Test 2:   0.000000   0.000000   0.000000 (  0.000529)
</pre>
<p>And that is all there is to know about simple benchmarking, on to<br />
profiling.</p>
<p><strong>Profiling</strong></p>
<p>Profiling takes benchmarking to the extreme. It tells you how much time each part of your code is take, and all you have to do is put:</p>
<pre class="brush: ruby; title: ; notranslate">
require 'profile'
</pre>
<p>at the top of your program!</p>
<pre class="brush: ruby; title: ; notranslate">
require 'profile'

class MyMath
    # Don't worry about the math, just the profiling output
    # We repeat the code to make it use up more time
    def self.x_offset angle, distance
        1000.times { distance * Math.sin(angle * Math::PI/180) }
    end

    def self.y_offset angle, distance
        1000.times { distance * Math.cos(angle * Math::PI/180) * -1 }
    end
end

MyMath.x_offset(220, 50)
MyMath.y_offset(220, 50)
</pre>
<p>And from the profiling output, we can see what took the longest:</p>
<pre class="brush: plain; title: ; notranslate">
%   cumulative   self              self     total
time   seconds   seconds    calls  ms/call  ms/call  name
72.41     0.21      0.21        2   105.00   145.00  Integer#times
10.34     0.24      0.03     4000     0.01     0.01  Fixnum#*
6.90     0.26      0.02     1000     0.02     0.02  Math.cos
6.90     0.28      0.02     2000     0.01     0.01  Float#/
3.45     0.29      0.01     1000     0.01     0.01  Float#*
0.00     0.29      0.00        1     0.00   140.00  MyMath#y_offset
0.00     0.29      0.00        1     0.00   150.00  MyMath#x_offset
0.00     0.29      0.00        1     0.00     0.00  Class#inherited
0.00     0.29      0.00     1000     0.00     0.00  Math.sin
0.00     0.29      0.00        2     0.00     0.00  Kernel.singleton_method_added
0.00     0.29      0.00        1     0.00   290.00  #toplevel
</pre>
<p>And that is it for today&#8217;s episode!</p>
<p>Please do not forget to show your appreciation by donating.</p>
<p>If you have any thing to say about anything related to Man With Code<br />
or these videos, please leave a comment below, or email me at<br />
tyler@manwithcode.com</p>
<p>Thanks for watching, Bye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/216/programming-with-ruby-episode-16-benchmarking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<item>
		<title>Programming With Ruby Episode 15, Error Handling</title>
		<link>http://manwithcode.com/211/programming-with-ruby-episode-15-error-handling/</link>
		<comments>http://manwithcode.com/211/programming-with-ruby-episode-15-error-handling/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 08:23:20 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[handling]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=211</guid>
		<description><![CDATA[Covered in this Episode: What are errors What is error handling begin&#8230;end rescue ensure raise Transcript: Hello Everybody and welcome to Programming With Ruby Episode 15, Error Handling. I&#8217;m Tyler and this video is brought to you by manwithcode.com. In this episode you will learn what exactly errors are, and what error handling is. You [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/97zxHTwEk6g&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/97zxHTwEk6g&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><strong>Covered in this Episode:</strong></p>
<ul>
<li>What are errors</li>
<li>What is error handling</li>
<li>begin&#8230;end</li>
<li>rescue</li>
<li>ensure</li>
<li>raise</li>
</ul>
<p><strong>Transcript:</strong></p>
<p>Hello Everybody and welcome to Programming With Ruby Episode 15, Error<br />
Handling. I&#8217;m Tyler and this video is brought to you by<br />
manwithcode.com.</p>
<p>In this episode you will learn what exactly errors are, and what error<br />
handling is. You will also be learning how to use the begin&#8230;end,<br />
rescue, and ensure keywords, as well as the raise method.</p>
<p>Lets get started!</p>
<p><strong>What are Errors?</strong></p>
<p>There are two types of problems with programs. #1 is bugs, and #2 is<br />
errors. You&#8217;ve most likely heard of both of these types of problems<br />
before. But what are they?</p>
<p>Bugs are more subtle problems, the program still runs and acts<br />
normally, but it may be outputting the wrong data, or messing<br />
something else up. It is completely up to the programmer to find these<br />
bugs.</p>
<p>Errors actually stop the program from running, or at least running all<br />
the way through. There are ways of handling most types of errors,<br />
which you will be learning about in this episode.</p>
<p><strong>What is error handling?</strong></p>
<p>It is possible to catch some types of errors, which when left alone,<br />
would otherwise result in your program crashing.</p>
<p>Error handling is the process of catching those errors, and usually<br />
doing something about them, like informing the user, or executing on a<br />
contingency plan.</p>
<p>There are many things that can create errors, such as trying to read<br />
from a file that doesn&#8217;t exist, a user entering bad data, trying to<br />
call a method that does not exist, and the list goes on.</p>
<p>Some errors you can combat by using methods like File.exists? to check<br />
if a file exists before trying to open it. But there are other cases<br />
where this is not an option, or where you prefer to handle the problem<br />
a different way. In this episode I will show you how.</p>
<p><strong>Real Code</strong></p>
<p>Error handling starts with the begin&#8230;end block which looks like this:</p>
<pre class="brush: ruby; title: ; notranslate">
begin
    # Code here
end
</pre>
<p>In that block is where you put the code that has the possibility of<br />
generating an error. That block in itself doesn&#8217;t do anything, to<br />
actually handle the errors, you need to use the rescue keyword.</p>
<pre class="brush: ruby; title: ; notranslate">
begin
    # Possibly error inducing code here
rescue
    # What to do if an error happens
end
</pre>
<p>What ever is between &#8220;rescue&#8221; and &#8220;end&#8221; will be executed if an error<br />
occurs. But what if you have the potential for multiple errors? Then<br />
you must use multiple rescues specifying the error the handle:</p>
<pre class="brush: ruby; title: ; notranslate">
begin
    # Possibly error inducing code
rescue ArgumentError
    # If ArgumentError is raised
rescue NoMethodError
    # If NoMethodError is raised
end
</pre>
<p>What if you don&#8217;t know the exact name of the error? Either create the<br />
error yourself and look at the output when the program crashes. Go to<br />
<a title="Ruby Documentation" href="http://ruby-doc.org">http://ruby-doc.org</a> and find all classes ending Error. Or consult<br />
<a title="List of Errors" href="http://www.zenspider.com/Languages/Ruby/QuickRef.html#34">http://www.zenspider.com/Languages/Ruby/QuickRef.html#34</a></p>
<p>Now lets say you want something to happen regardless of whether or not<br />
the code generates an error. Say maybe you have to close a file, or<br />
end your connection to a database. Then you would want to use ensure!</p>
<pre class="brush: ruby; title: ; notranslate">
begin
    # ...
rescue
    # ...
ensure
    # This gets executed no matter what
end
</pre>
<p>Now that you know how to handle errors, how do you go about raising<br />
errors of your own? With raise, of course!</p>
<pre class="brush: ruby; title: ; notranslate">
def mymethod data
    if data.is_malformed?
        raise ArgumentError
    end
end
</pre>
<p>Why would you want to do this? It can serve as a better reminder to<br />
you or other programmers using your code that what they were doing is<br />
wrong. This can help stop bugs.</p>
<p>This brings us to the end of the episode.</p>
<p>If you have any questions, comments, or suggestions about anything<br />
related to Man With Code or these video tutorials; Please leave a<br />
comment below, or email me at tyler@manwithcode.com</p>
<p>Do not forget to donate. A lot of time and hard work went into making<br />
these. If you liked these videos the best way to show your<br />
appreciation is by donating.</p>
<p>Thanks for watching, goodbye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/211/programming-with-ruby-episode-15-error-handling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<item>
		<title>Programming With Ruby Episode 14, YAML</title>
		<link>http://manwithcode.com/205/programming-with-ruby-episode-14-yaml/</link>
		<comments>http://manwithcode.com/205/programming-with-ruby-episode-14-yaml/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 08:14:03 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[storing]]></category>
		<category><![CDATA[yaml]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=205</guid>
		<description><![CDATA[Covered in this Episode: What is YAML Why should you use YAML? Storing Data Transcript: Hello Everybody and welcome to Programming With Ruby Episode 14, YAML. I&#8217;m Tyler and this video is brought to you by manwithcode.com. I will start off this episode telling you what YAML is and why you should be using it. [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/NSifr3DflxQ&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/NSifr3DflxQ&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><strong>Covered in this Episode:</strong></p>
<ul>
<li>What is YAML</li>
<li>Why should you use YAML?</li>
<li>Storing Data</li>
</ul>
<p><strong>Transcript:<br />
</strong></p>
<p>Hello Everybody and welcome to Programming With Ruby Episode 14,<br />
YAML. I&#8217;m Tyler and this video is brought to you by manwithcode.com.</p>
<p>I will start off this episode telling you what YAML is and why you<br />
should be using it. I will then be showing you how you can store<br />
objects and various assorted other kinds of data using YAML.</p>
<p>Without further delay, lets get started!</p>
<p><strong>What is YAML?</strong></p>
<p>YAML stands for YAML Ain&#8217;t Markup Language. In the most basic sense it<br />
is a way of storing data for later use.</p>
<p><strong>Why should you use YAML?</strong></p>
<p>Lets say you are writing a game, you could save your players progress<br />
to a YAML file. Or if your writing an application with many preference<br />
settings, you might save the user&#8217;s preferences to a YAML file.</p>
<p>Using YAML instead of creating your own text-based format creates more<br />
portability, because other applications can immediately use your YAML<br />
file instead of having to write their own custom file loader.</p>
<p>YAML also makes editing files by hand very easy to do if you have to.</p>
<p>Enough of all the theoretical talk, lets write some code!</p>
<p><strong>Storing Data</strong></p>
<p>Lets say we are writing a text editor and there are a few preferences the<br />
user can change. We want the user to be able to set their preferences and<br />
have them saved, so the next time they start up our text editor the<br />
preferences are set the same as they were at last use.</p>
<p>We decide to use YAML to store our users preferences. Lets say for<br />
example that the preferences are stored in a hash:</p>
<pre class="brush: ruby; title: ; notranslate">
@preferences = {&quot;word-wrapping&quot; =&gt; true, &quot;font-size&quot; =&gt; 20, &quot;font&quot; =&gt; &quot;Arial&quot;}
</pre>
<p>To save that using YAML we have to use:</p>
<pre class="brush: ruby; title: ; notranslate">
require 'yaml'
</pre>
<p>Open a file for writing (YAML files end in .yml or .yaml):</p>
<pre class="brush: ruby; title: ; notranslate">
output = File.new('prefs.yml', 'w')
</pre>
<p>Use the YAML.dump method to get the text that will be outputted:</p>
<pre class="brush: ruby; title: ; notranslate">
output.puts YAML.dump(@preferences)
output.close
</pre>
<p>Full source:</p>
<pre class="brush: ruby; title: ; notranslate">
require 'yaml'
@preferences = {&quot;word-wrapping&quot; =&gt; true, &quot;font-size&quot; =&gt; 20, &quot;font&quot; =&gt; &quot;Arial&quot;}

output = File.new('prefs.yml', 'w')
output.puts YAML.dump(@preferences)
output.close
</pre>
<p>And that is how easy it is to store data!</p>
<p>We read back a file in a similar way, using the YAML.load method:</p>
<pre class="brush: ruby; title: ; notranslate">
require 'yaml'

output = File.new('prefs.yml', 'r')
@preferences = YAML.load(output.read)
output.close
</pre>
<p>Don&#8217;t think you&#8217;re limited to simple data like hashes and arrays, you<br />
can store objects too!</p>
<p>It has been my experience that it is usually best to store data in<br />
hashes, because they automatically have a label, unlike an array. You<br />
can do whatever you want to, but that is my recommendation.</p>
<p>Now comes the sad time when we have to close the episode.</p>
<p>Please don&#8217;t forget to donate, a few dollars can go a long way.</p>
<p>If you have any questions, comments or suggestions, please do not<br />
hesitate to leave a comment below or email me at tyler@manwithcode.com</p>
<p>Thank for watching!</p>
<p>Bye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/205/programming-with-ruby-episode-14-yaml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<item>
		<title>Programming With Ruby Episode 13, Basic I/O</title>
		<link>http://manwithcode.com/197/programming-with-ruby-episode-13-basic-io/</link>
		<comments>http://manwithcode.com/197/programming-with-ruby-episode-13-basic-io/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 08:07:03 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[directories]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[io]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=197</guid>
		<description><![CDATA[Covered in this Episode: Defining I/O Files Directories Transcript: Hello Everybody and welcome to Programming With Ruby Episode 13, Basic input output. As always, I&#8217;m Tyler and this video is brought to you by manwithcode.com In this episode I will be defining what exactly input/output is, You will also learn how to work with files [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/x-ru_Hw7YNI&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/x-ru_Hw7YNI&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><strong>Covered in this Episode:</strong></p>
<ul>
<li>Defining I/O</li>
<li>Files</li>
<li>Directories</li>
</ul>
<p><strong>Transcript:</strong></p>
<p>Hello Everybody and welcome to Programming With Ruby Episode 13, Basic<br />
input output. As always, I&#8217;m Tyler and this video is brought to you by<br />
manwithcode.com</p>
<p>In this episode I will be defining what exactly input/output is, You<br />
will also learn how to work with files and directories in Ruby</p>
<p>Lets get started!</p>
<p><strong>Defining I/O</strong></p>
<p>So what exactly is I/O or input/output. Basically Input is any data that<br />
you receive from the user, and output is what data you give to the<br />
user, usually based on what input the user gave you.</p>
<p>In this episode you will be seeing I/O as working with files and<br />
directories. You have already worked with I/O previously when we<br />
talked about getting strings from the user (gets) and printing string<br />
to the screen (puts)</p>
<p><strong>Files</strong></p>
<p>There are a couple of ways to start working with files. The first is<br />
by using File.new:</p>
<pre class="brush: ruby; title: ; notranslate">
my_file = File.new('file', 'r')
my_file.close
</pre>
<p>File.new opens the file (the first parameter), for the specified mode<br />
(the second parameter)</p>
<p>The file name you use can be either just the relative file name<br />
(notes.txt) or the full path to the file (C:\Documents and<br />
Settings\Tyler\My Documents\notes.txt). Just remember that if you use<br />
only the file name, that file must be in the same folder your program<br />
is located in!</p>
<p>The mode defines how you are going to use the file you&#8217;ve opened. In<br />
the example &#8216;r&#8217; is used. Which stands for read, meaning we are only<br />
going to read from the file.</p>
<p>&#8216;w&#8217; is write meaning we are writing to the file specified, be careful<br />
when using write mode, as the whole file is cleared when it is opened.</p>
<p>&#8216;a&#8217; is append, which is similar to write, except instead of clearing<br />
the whole file, it appends all written data to the end.</p>
<p>All the different modes can have &#8216;+&#8217; at the end of them, which opens<br />
up both read and write functionality. (ex: &#8216;w+&#8217;)</p>
<p>Now you know how to open a file, how exactly do yo go about writing to<br />
it? By simply using puts and print, like you did when outputting data<br />
to the screen, except they output data to the file!</p>
<pre class="brush: ruby; title: ; notranslate">
my_file = File.new('example.txt', 'w')
my_file.puts &quot;Hello World!&quot;
my_file.close
</pre>
<p>If you want to read from a file you can use File.read:</p>
<pre class="brush: ruby; title: ; notranslate">
my_file = File.new('example.txt', 'r')
puts my_file.read
my_file.close
</pre>
<p>You can also pass in how many characters you want to read as a parameter.</p>
<p>If you would rather have the lines of a file in an array, you can use<br />
file.readlines.</p>
<p>If you are unsure a file exists you can simply use File.exists?:</p>
<pre class="brush: ruby; title: ; notranslate">
File.exists(&quot;notes.txt&quot;)
</pre>
<p>Now it is important to note that every time I am done using a file I<br />
call the .close method, why do I do this? Because if you don&#8217;t close<br />
your access on the file, it can become unusable by other<br />
programs. Also, your computers operating system might not write the<br />
changes you&#8217;ve made to the file, until your program has released its<br />
hold on it.</p>
<p>As an alternative to using file.close every single time, we can use<br />
File.open, instead of File.new. File.open lets us use the file in a<br />
code block, at the end of the code block, the file is closed<br />
automatically.</p>
<pre class="brush: ruby; title: ; notranslate">
File.open('hello.txt', 'w') do |file|
    file.puts &quot;Hello World!&quot;
end
</pre>
<p>There is a whole lot more you can do with files in Ruby to learn more<br />
go to http://ruby-doc.org/core-1.8.7/index.html and find the File and IO class</p>
<p><strong>Directories</strong></p>
<p>You can work with directories (also known as folders) in Ruby using<br />
Dir. You can create directories with Dir.mkdir:</p>
<pre class="brush: ruby; title: ; notranslate">
Dir.mkdir(&quot;Hello&quot;)
</pre>
<p>You can get an array of all the files and directories that are in the<br />
current directory with Dir.entries:</p>
<pre class="brush: ruby; title: ; notranslate">
Dir.entries('.')
</pre>
<p>Keep in mind that . is your current directory, and .. is the directory<br />
one level above the current one. Also, like files you can specify the<br />
relative path or the full path.</p>
<p>There is also another method similar to Dir.entries, Dir.foreach. They<br />
are essentially the same, except foreach allows you to iterate over<br />
each item in a code block.</p>
<pre class="brush: ruby; title: ; notranslate">
Dir.foreach('.') do |entry|
    puts entry
end
</pre>
<p>Like Files, there is a lot of material I couldn&#8217;t cover to learn more<br />
go to http://ruby-doc.org/core-1.8.7/index.html and find the Dir class</p>
<p>This brings us to the end of the episode.</p>
<p>If you like these videos please donate.</p>
<p>And if you have any Questions, Comments or Suggestions, you can leave<br />
a comment in the comment box below, or email me at<br />
tyler@manwithcode.com</p>
<p>Thank you very much for watching, goodbye.</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/197/programming-with-ruby-episode-13-basic-io/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<item>
		<title>Programming With Ruby Episode 12, Documentation</title>
		<link>http://manwithcode.com/183/programming-with-ruby-episode-12-documentation/</link>
		<comments>http://manwithcode.com/183/programming-with-ruby-episode-12-documentation/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 06:07:45 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[rdoc]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=183</guid>
		<description><![CDATA[Covered In This Episode: Comments RDoc Transcript: Hello Everybody and welcome to Programming With Ruby Episode 12, Documentation. I&#8217;m Tyler and this video is brought to you by manwithcode.com. In this episode I will be talking about documenting your code, more specifically with comments, and using the tool rdoc. This should be a short show, [...]]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/BEdmtC03who&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/BEdmtC03who&#038;hl=en&#038;fs=1" 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>Comments</li>
<li>RDoc</li>
</ul>
<p><strong>Transcript:<br />
</strong></p>
<p>Hello Everybody and welcome to Programming With Ruby Episode 12,<br />
Documentation. I&#8217;m Tyler and this video is brought to you by<br />
manwithcode.com.</p>
<p>In this episode I will be talking about documenting your code, more<br />
specifically with comments, and using the tool rdoc.</p>
<p>This should be a short show, so lets get started!</p>
<p><strong>Comments</strong></p>
<p>You&#8217;ve seen comments throughout these video tutorials. They were the<br />
lines with the hash mark that are ignored by Ruby.</p>
<p>Comments are generally used to explain code to other developers<br />
(including yourself). Ruby already makes code very easy to understand<br />
in the first place. You can also help this by naming your methods and<br />
variables sensibly. But there are times when this is not enough.</p>
<p>Sometimes you end up doing something very complicated, such as a long<br />
regular expression, some SQL magic, or any other possibly difficult to<br />
understand piece of code. Those can be times when comments are needed.</p>
<p>Comments are also needed for when you are making code for other<br />
developers to use. When they are using your code and not developing it<br />
along with you, they can care less about finding how it works. They<br />
just want a comment that can tell them what your class/method/piece of<br />
code/whatever does, and how to make it do it.</p>
<p>Tools like rdoc can help you make your code&#8217;s documentation even<br />
better, and that is what we are going to talk about next.</p>
<p><strong>Rdoc</strong></p>
<p>Rdoc should be installed already from when you installed ruby. If not<br />
you can install it via rubygems or your platforms package manager.</p>
<p>Rdoc is a tool that generates very nice looking documentation for your<br />
projects.</p>
<p>First just run the command rdoc in a directory with code files in it.</p>
<p>rdoc will create a folder named &#8220;doc&#8221; and your documentation will be<br />
that folder. If you go into doc and open up index.html in your<br />
browser, you will see the generated documentation.</p>
<p>You will probably notice that rdoc didn&#8217;t pick up any of the comments<br />
inside your code, only those right above the definitions of classes,<br />
methods, or modules.</p>
<p>You may also notice that the descriptions might not be formatted very<br />
well. You can spice it up by using rdoc markup found at:</p>
<p>http://rdoc.rubyforge.org/RDoc.html</p>
<p>I&#8217;m not going to go too much farther into rdoc, as it is not an<br />
essential tool for development. It can be, however, very useful. So<br />
please take some time to learn more about it!</p>
<p>This brings us to the end of the show.</p>
<p>Please don&#8217;t forget to donate!</p>
<p>If you have any questions, comments, or suggestions you can leave them<br />
in the comment box below or email me at tyler@manwithcode.com</p>
<p>Thank you very much for watching, goodbye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/183/programming-with-ruby-episode-12-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<item>
		<title>Programming With Ruby Episode 11, Ruby Projects</title>
		<link>http://manwithcode.com/176/programming-with-ruby-episode-11-ruby-projects/</link>
		<comments>http://manwithcode.com/176/programming-with-ruby-episode-11-ruby-projects/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 06:00:31 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[require]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rubyforge]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=176</guid>
		<description><![CDATA[Covered In This Episode: Finding projects (GitHub, RubyForge) Using Rubygems Using the code Transcript: Hello Everybody and welcome to Programming With Ruby Episode 11, Ruby Projects. I&#8217;m Tyler, and this video is brought to you by manwithcode.com. Despite what the name may imply, this episode is not about making projects in ruby, but finding and [...]]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/_F0UHFpk2R0&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/_F0UHFpk2R0&#038;hl=en&#038;fs=1" 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>Finding projects (GitHub, RubyForge)</li>
<li>Using Rubygems</li>
<li>Using the code</li>
</ul>
<p><strong>Transcript:</strong></p>
<p>Hello Everybody and welcome to Programming With Ruby Episode 11, Ruby<br />
Projects. I&#8217;m Tyler, and this video is brought to you by<br />
manwithcode.com.</p>
<p>Despite what the name may imply, this episode is not about making<br />
projects in ruby, but finding and using projects other people have<br />
made. I will be showing you <a href="http://rubyforge.org">rubyforge.org</a> and <a href="http://github.com">github.com</a>, both places<br />
have many different and useful projects hosted.</p>
<p>I will also be showing you how to use rubygems, arguably the easiest<br />
and most popular way of installing, managing, and keeping up to date<br />
various ruby libraries, tools, etc. which rubygems calls gems.</p>
<p>And finally you will learn how to use the code you find!</p>
<p>Lets get started!</p>
<p><strong>Finding Projects &#8211; Rubyforge</strong></p>
<p>Rubyforge is one of the most popular hosting sites for ruby<br />
projects. (It is also where most gems are hosted)</p>
<p>Just navigate over to <a href="http://rubyforge.org">http://rubyforge.org</a> to get started</p>
<p>If you want to find a project, you have a few options. First is the<br />
search box located at the top right of the website.</p>
<p>Second is the project tree where you can find projects by the category<br />
they are in.</p>
<p>Third is the most popular projects on the homepage, which can be<br />
helpful from time to time.</p>
<p>If you find a project that you like, you can download it, or install<br />
it as a gem if it is available. Both of which will be covered a little<br />
later in this tutorial.</p>
<p><strong>Finding Projects &#8211; GitHub</strong></p>
<p>Github is another project hosting site, that easily lets developers<br />
collaborate using the version control system, git. Github has been<br />
gaining a lot of popularity with Ruby programmers lately and you can<br />
find many Ruby projects here.</p>
<p>GitHub is located at <a href="http://github.com">http://github.com</a></p>
<p>GitHub has search functionality, and most popular like Rubyforge, but<br />
it is a little more comprehensive.</p>
<p>GitHub also offers nice graphs and many download options depending on<br />
your needs.</p>
<p><strong>Using Rubygems</strong></p>
<p>To start using rubygems, first you have to install it. If you<br />
installed via a one-click installer you probably already have it. To<br />
check if you have it installed, open your command prompt and enter<br />
&#8220;gem&#8221;. If nothing comes up, it is not installed.</p>
<p>If you are on Debian or a variant of it (such as Ubuntu) this command<br />
will get you rubygems: sudo apt-get install rubygems</p>
<p>Otherwise go to <a href="http://rubygems.org">http://rubygems.org/</a> and download rubygems from there.</p>
<p>After you&#8217;ve installed, run the command:<br />
gem</p>
<p>to make sure the installation succeed. If not you may have to add<br />
rubygems to your PATH, a quick Google search will tell you how.</p>
<p>For this example I you will install the gem hpricot, which parses HTML.<br />
simply use the command:<br />
gem install hpricot<br />
or<br />
sudo gem install hpricot</p>
<p>It should install successfully, and now you can start using it in your code!</p>
<p>But before we do that, I would like to show you a few more features or rubygems.</p>
<p>&#8220;gem list&#8221; lists all the gems you have installed<br />
&#8220;gem uninstall gem&#8221; uninstalls the specified gem<br />
&#8220;gem update&#8221; updates all your gems<br />
&#8220;gem help commands&#8221; shows all commands that rubygems has, so you can<br />
explore on your own!</p>
<p><strong>Using the code</strong></p>
<p>Now that you have installed a gem, or downloaded a projects source<br />
code, you can use it in your own programs.</p>
<p>To obtain access to an installed gem, or the source file add the<br />
following line to the top of your program:</p>
<pre class="brush: ruby; title: ; notranslate">
require 'rubygems'
require 'name' # Name can be a gem or a source file
</pre>
<p>if you are just using a source file, you don&#8217;t need to require rubygems<br />
example:</p>
<pre class="brush: ruby; title: ; notranslate">
require 'rubygems'
require 'hpricot'
</pre>
<p>If you are loading a file that can change, use load:<br />
load &#8216;name&#8217; # Name can be a gem or a source file</p>
<p>Note that I said source file. This means that you can separate your<br />
own code into different files and load them in using the load or<br />
require methods!</p>
<p>Now we have reached that sad sad time, when the episode starts ending.</p>
<p>If you have any question, comments, or suggestions leave a comment on<br />
this page, or send me an email at tyler@manwithcode.com</p>
<p>Please do not forget to donate, a small $5 or $10 donation will help<br />
more than you realize!</p>
<p>Thanks for watching, Goodbye.</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/176/programming-with-ruby-episode-11-ruby-projects/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<item>
		<title>Programming With Ruby Episode 10, Objects and Modules</title>
		<link>http://manwithcode.com/169/programming-with-ruby-episode-10-objects-and-modules/</link>
		<comments>http://manwithcode.com/169/programming-with-ruby-episode-10-objects-and-modules/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 05:55:13 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[open classes]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scope]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=169</guid>
		<description><![CDATA[Part 1: Part 2: Covered In This Episode Variable Scope Class creation Open Classes Class Inheritance Modules Transcript: Hello Everybody and welcome to Programming With Ruby Episode 10, Objects and Modules. As always, I&#8217;m Tyler and this video is brought to you by manwithcode.com Variable scope will be explained. In this episode I will be [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Part 1:</strong><br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/q75BiSgI6QI&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/q75BiSgI6QI&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
<strong>Part 2:</strong><br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/AmOj09AVI8k&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/AmOj09AVI8k&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
<strong>Covered In This Episode</strong></p>
<ul>
<li>Variable Scope</li>
<li>Class creation</li>
<li>Open Classes</li>
<li>Class Inheritance</li>
<li>Modules</li>
</ul>
<p><strong>Transcript:</strong></p>
<p>Hello Everybody and welcome to Programming With Ruby Episode 10,<br />
Objects and Modules. As always, I&#8217;m Tyler and this video is brought to<br />
you by manwithcode.com</p>
<p>Variable scope will be explained.</p>
<p>In this episode I will be going over class creation, I touched on this<br />
before but that was a while ago and I will also be going more in-depth</p>
<p>I will be teaching you what class inheritance is.</p>
<p>You will also find out what open classes are, and why they are useful.</p>
<p>You will learn what modules are, and how and when you should use them</p>
<p>Lets get started!</p>
<p><strong>Variable Scope</strong></p>
<p>I taught you about variables earlier, but I need to go a little more<br />
in-depth for you to be able to write real applications, and not be<br />
confused by some mysterious errors.</p>
<p>What is a variable scope? a variable scope is where the variable is<br />
available for use in the program. The code in classes and methods that<br />
you define have a different scope than the code outside<br />
them. Different scopes are introduced when classes and methods are<br />
defined.</p>
<p>There are 5 different types of variables:<br />
1. local variable ex: variable<br />
2. instance variable ex: @variable<br />
3. class variable ex: @@variable<br />
4. global variable ex: $variable<br />
5. constant variables ex: VARIABLE</p>
<p>A local variable is available in the scope in which it is defined. An<br />
instance variable is available in the instance of the class it was<br />
defined. A class variable is available from any instances of that<br />
class. A global variable is available anywhere. A constant is<br />
available anywhere, but can only be changed within the scope it was<br />
defined.</p>
<p><strong>Class Creation</strong></p>
<p>As mentioned in episode 4 you define classes like this, don&#8217;t forget<br />
that classes must start with an upper case letter:</p>
<pre class="brush: ruby; title: ; notranslate">
class MyClass
end
</pre>
<p>and create them like this:</p>
<pre class="brush: ruby; title: ; notranslate">
variable = MyClass.new
</pre>
<p>You can define methods inside the class:</p>
<pre class="brush: ruby; title: ; notranslate">
class MyClass
    def hello
        puts 'Hello!'
    end
end
</pre>
<p>If you define a method named &#8216;initialize&#8217;, that method is run when the<br />
class is instantiated. This is very useful in many situations, like<br />
creating a screen in a game or connecting to the database in a web<br />
application. This is also the usual place for defining instance variables</p>
<pre class="brush: ruby; title: ; notranslate">
class MyClass
    def initialize
        @database = connect_to_database
    end
end
</pre>
<p>A method defined with &#8216;self.&#8217; in front of it&#8217;s name is called a class<br />
method, because the method is available outside of the class, and you<br />
don&#8217;t have to instantiate an object. These can be useful for times<br />
when you don&#8217;t want create objects, or want certain information about<br />
all the instances of a class.</p>
<pre class="brush: ruby; title: ; notranslate">
class MyClass
    def self.game_objects
        # Return all objects in the game
    end
end
</pre>
<p><strong>Open Classes</strong></p>
<p>So now that you know more about creating classes, I would like to call<br />
your attention to a very useful feature of Ruby, Open Classes.</p>
<p>The term Open classes means you have the ability to add or substitute<br />
code in a class that is already defined. This is quite easy to do too,<br />
all you have to do is define a class in the same way you always do,<br />
just with a pre-existing class. You only have to define what you are<br />
adding, or overwriting, you don&#8217;t have to define the WHOLE class<br />
again.</p>
<p>Take for example, the String class. This class (obviously) is the<br />
class from which all strings are created. Lets say, for example that<br />
you had some code that took a string, and gave back an array that had<br />
each word in it. You could do this:</p>
<pre class="brush: ruby; title: ; notranslate">
def words(string)
    string.scan(/\w[\w\'\-]*/)
end
words(&quot;Hello World&quot;) #=&gt; [&quot;Hello&quot;, &quot;World&quot;]
</pre>
<p>But it looks a lot nicer, and is more object-oriented if you do this instead:</p>
<pre class="brush: ruby; title: ; notranslate">
class String
    def words
        scan(/\w[\w\'\-]*/)
    end
end
&quot;Hello World&quot;.words #=&gt; [&quot;Hello&quot;, &quot;World&quot;]
</pre>
<p>You can probably see why this can be useful.</p>
<p>Be careful though, if you override existing functionality, you run the<br />
risk of breaking that functionality in your code, and all the external<br />
code your project uses.</p>
<p><strong>Class Inheritance</strong></p>
<p>Lets say you are making a video game. In that game you will have many<br />
different types of enemies.</p>
<p>Now, odds are that all your enemies will have stuff in common. They<br />
probably will all have health, ammo, etc. They all will have to draw<br />
themselves on the screen, animate when they move, etc.</p>
<p>So you can see that with many different types of enemies, you would<br />
have to have lots of duplicate code in each class. This is solved via<br />
class inheritance. Class inheritance allows you to write one class<br />
that contains all the common code. Then when you create other classes<br />
you can specify that those classes will use (inherit) that common<br />
code.</p>
<p>You specify if a class is inheriting from another by following the<br />
class name, with a less than sign followed by the name of the class<br />
you are inheriting from.</p>
<p>You can also re-implement some of that common code, if needed.</p>
<p>For example:</p>
<pre class="brush: ruby; title: ; notranslate">
class Enemy
    def draw
        # Drawing Code
    end
end

class Soldier &lt; Enemy
    def move
    end

    def shoot
    end
end

class DifferentEnemy &lt; Enemy
    def draw
        # Changes the draw functionality, only for this class
    end
end
</pre>
<p>Another thing to keep in mind, if you redefine the initialize method<br />
in your inherited class, you must call the super method.</p>
<p><strong>Modules</strong></p>
<p>Modules are like classes, except they can&#8217;t be initialized, and every<br />
method has to be prefixed with &#8220;self.&#8221; like class methods.</p>
<p>This limitation in functionality may make you wonder when modules are<br />
ever useful. There are actually only a few times. First is to keep<br />
parts of your code separated. The more important second reason is when<br />
you are creating a library of code for others to use. This is so the<br />
functionality in the library isn&#8217;t stepping over or redefining classes<br />
you have already defined (if they happen to have the same name).</p>
<p>You define modules just like you do classes, except using the module keyword:</p>
<pre class="brush: ruby; title: ; notranslate">
module DataVisualizer
    class Grapher
    end

    class Plotter
    end

    def self.data_compatible?
    end
end
</pre>
<p>To access methods that modules define you simply do:</p>
<pre class="brush: ruby; title: ; notranslate">
module MyModule
    def self.x
    end
end
MyModule.x
</pre>
<p>To access classes defined by modules, you have to use double colons:</p>
<pre class="brush: ruby; title: ; notranslate">
module DataVisualizer
    class Grapher
    end

    class Plotter
    end
end

DataVisualizer::Grapher.new
</pre>
<p>That&#8217;s all there is to know about modules, meaning this is the end of<br />
the episode!</p>
<p>Please donate, those these videos are free, it costs money to make them.</p>
<p>If you have any questions comments or suggestions about anything<br />
related to Man With Code or the Ruby tutorials, you can leave a<br />
comment on this page or email me at tyler@manwithcode.com</p>
<p>Than you very much for watching, goodbye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/169/programming-with-ruby-episode-10-objects-and-modules/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<item>
		<title>Programming With Ruby Episode 9, Flow Control</title>
		<link>http://manwithcode.com/149/programming-with-ruby-episode-9-flow-control/</link>
		<comments>http://manwithcode.com/149/programming-with-ruby-episode-9-flow-control/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 10:24:19 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[blocks]]></category>
		<category><![CDATA[case]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[else]]></category>
		<category><![CDATA[flow]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[until]]></category>
		<category><![CDATA[when]]></category>
		<category><![CDATA[while]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=149</guid>
		<description><![CDATA[Part 1: Part 2: Covered in this episode: Code Blocks if, else, unless case, when while, until, for loops Transcript: Hello everybody and welcome to Programming With Ruby Episode 9, Flow Control. I&#8217;m Tyler and this video is brought to you by manwithcode.com So far all of the programs and code that I have shown [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Part 1:</strong><br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/6uMw60C7tyY&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/6uMw60C7tyY&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><strong>Part 2:</strong><br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/zpqByOutHVU&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/zpqByOutHVU&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><strong>Covered in this episode:</strong></p>
<ul>
<li>Code Blocks</li>
<li>if, else, unless</li>
<li>case, when</li>
<li>while, until, for loops</li>
</ul>
<p><strong>Transcript:</strong></p>
<p>Hello everybody and welcome to Programming With Ruby Episode 9, Flow<br />
Control. I&#8217;m Tyler and this video is brought to you by manwithcode.com</p>
<p>So far all of the programs and code that I have shown you has been<br />
completely linear. There has been no way to loop based on a condition<br />
or do something based on what the user inputs.</p>
<p>In this episode I will be showing you how to do all this, and I will<br />
also be explaining to you what a code block is, since I&#8217;ve been<br />
mentioning them in almost every episode previous to this.</p>
<p>This episode is REALLY LONG! Feel free to pause the video and think<br />
about what&#8217;s been said or try out code yourself.</p>
<p><strong>Code Blocks</strong></p>
<p>Throughout the previous videos, I&#8217;ve been telling you about code<br />
blocks, I&#8217;ve also been telling you I&#8217;ll teach you what they are in a<br />
later episode. That episode has finally come.</p>
<p>Code blocks look something like this:</p>
<pre class="brush: ruby; title: ; notranslate">
my_array.each do |item|
    puts item
end
</pre>
<p>or like this:</p>
<pre class="brush: ruby; title: ; notranslate">
my_array.each { |item| puts item }
</pre>
<p>Both of those actually do the same thing! The .each method takes a<br />
block as an argument. The block is what is between the do and end<br />
keywords, or the curly braces, depending on which format you use.</p>
<p>The item between the pipe characters (which is above the ENTER key) is<br />
the variable the .each method gives you (in this case the item in the<br />
array).</p>
<p>The rest of the code block is just normal Ruby code. Not so complicated, eh?</p>
<p>(Keep in mind that there are more metheds besides .each that take code blocks)</p>
<p><strong>If, Else, and Unless</strong></p>
<p>A basic if statement would look like this:</p>
<pre class="brush: ruby; title: ; notranslate">
x = 3
if x &lt; 5
    # Do something
end
</pre>
<p>The &#8220;x &lt; 5&#8243; is the condition that has to be true for the code to<br />
run. If that condition is true, the code between the &#8220;if&#8221; and &#8220;end&#8221;<br />
keywords is run.</p>
<p>There are many different conditional operators you can use:</p>
<pre class="brush: ruby; title: ; notranslate">
==
&lt;
&gt;
&lt;=
&gt;=
!=
</pre>
<p>Just be sure to keep in mind that the &#8220;is equal&#8221; operator uses two<br />
equal signs, not one.</p>
<p>If you would like code that is run when the condition is false:</p>
<pre class="brush: ruby; title: ; notranslate">
x = 3
if x &lt; 5
    # Do something if true
else
    # Do something if false
end
</pre>
<p>In a similar way you can execute code if the first condition is false<br />
but a second is true:</p>
<pre class="brush: ruby; title: ; notranslate">
x = 3
if x &lt; 5
    # Do something if true
elsif x == 3
    # Do something if the first is false and this is true
else
    # Do something in all are false
end
</pre>
<p>In a different way you can only execute the code if two conditions are true:</p>
<pre class="brush: ruby; title: ; notranslate">
x = 3
y = 2
if x == 3 and y == 2
    # Do something
end
</pre>
<p>You can also only execute code if one of any conditions are true:</p>
<pre class="brush: ruby; title: ; notranslate">
x = 3
y = 4
if x == 3 or y == 2
    # Do something
end
</pre>
<p>There is also the evil twin brother of if, unless:</p>
<pre class="brush: ruby; title: ; notranslate">
x = 3
unless x == 3
    # if x is 3, this code will not run
end
</pre>
<p>You can chain all of these together in almost any way you choose.</p>
<p><strong>Case, When</strong></p>
<p>Another way to evaluate conditions is using case, when:</p>
<pre class="brush: ruby; title: ; notranslate">
x = 3
case x
    when 1 then
        # do something
    when 3 then
        # do something
    else
        # do something if none are true
end
</pre>
<p>You can&#8217;t do many complex conditionals, but it can be nicer than a<br />
long chain of if, else&#8217;s</p>
<p><strong>while, until, and for loops</strong></p>
<p>Similarly to the above if statements, while, until, and for loops will<br />
execute code based on a condition, but they will do it multiple times.</p>
<p>while:</p>
<pre class="brush: ruby; title: ; notranslate">
x = 1
while x &lt; 5
    x += 1
    puts x
end
</pre>
<p>Similar to the relationship between if, and unless. while has an evil<br />
sister, until</p>
<pre class="brush: ruby; title: ; notranslate">
x = 1
until x &gt; 5
    x += 1
    puts x
end
</pre>
<p>There are also for loops, which allow you to iterate over something</p>
<pre class="brush: ruby; title: ; notranslate">
foods = [&quot;ham&quot;, &quot;eggs&quot;, &quot;cheese&quot;]
for food in foods
    puts food += &quot; is yummy!&quot;
end
</pre>
<p>There is also .each, for&#8217;s evil stepchild:</p>
<pre class="brush: ruby; title: ; notranslate">
foods = [&quot;ham&amp;&quot;, &quot;eggs&quot;, &quot;cheese&quot;]
foods.each do |food|
    puts food += &quot; is yummy!&quot;
end
</pre>
<p><strong>Concrete Example</strong></p>
<p>A menu system</p>
<pre class="brush: ruby; title: ; notranslate">
input = &quot;&quot;
until input == 'quit'
    puts &quot;
Menu
(1) Hi!
(2) Credits
(3 or quit) Exit
&quot;
    input = gets.chomp!
    case input
        when &quot;1&quot; then
            puts &quot;Hi!&quot;
        when &quot;2&quot; then
            puts &quot;Written By: Tyler&quot;
        when &quot;3&quot; then
            input = 'quit'
        else
            puts &quot;Invalid input&quot;
    end
end
</pre>
<p><em>Lets break it down.</em></p>
<p>First we set the input variable to an empty string (so the second line<br />
dosen&#8217;t give us an error)</p>
<p>Then we use an until loop that quits when input is equal to &#8216;quit&#8217;</p>
<p>Next we print the menu (which is unindented so it doesn&#8217;t print to the<br />
screen indented)</p>
<p>After that we get input from the user, use .chomp! to remove the<br />
newline character created from pressing ENTER, and put the input into<br />
the input variable</p>
<p>Then we have a case statement, when &#8220;1&#8243; we print &#8220;Hi!&#8221;, when &#8220;2&#8243; we<br />
print who it was created by, when &#8220;3&#8243; we quit, otherwise we print out<br />
&#8220;Invalid input&#8221; to tell the user they entered something wrong.</p>
<p>This brings us to the end of the video.</p>
<p>If you like these videos please donate, because I&#8217;m doing this all for free</p>
<p>If you have any questions, comments, or suggestions, you can leave a<br />
comment on this page. Or you can email me at tyler@manwithcode.com</p>
<p>I covered a lot of material in this episode and I urge you to watch it<br />
again, go to the original post and look at the code (link is in the<br />
description) and write some code yourself.</p>
<p>Thank you very much for watching, goodbye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/149/programming-with-ruby-episode-9-flow-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<item>
		<title>Extra Info About manwithcode.com</title>
		<link>http://manwithcode.com/146/extra-info/</link>
		<comments>http://manwithcode.com/146/extra-info/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 00:38:37 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[extra]]></category>
		<category><![CDATA[info]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=146</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/WKQUQxdjSIY&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/WKQUQxdjSIY&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/146/extra-info/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming With Ruby Episode 8, Hashes</title>
		<link>http://manwithcode.com/132/programming-with-ruby-episode-8-hashes/</link>
		<comments>http://manwithcode.com/132/programming-with-ruby-episode-8-hashes/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 06:33:11 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[hashes]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=132</guid>
		<description><![CDATA[Covered In This Episode: What are Hashes? Hash Creation Hash Accessing Hash iteration Hash Methods Transcript: Hello Everybody and welcome to Programming With Ruby Episode 8, Hashes. I&#8217;m Tyler,and this video is brought to you by, manwithcode.com In this episode I will be telling you what hashes are, how you can create them, access them, [...]]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/LIrTu1UDATk&#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/LIrTu1UDATk&#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 are Hashes?</li>
<li>Hash Creation</li>
<li>Hash Accessing</li>
<li>Hash iteration</li>
<li>Hash Methods</li>
</ul>
<p><strong>Transcript:</strong></p>
<p>Hello Everybody and welcome to Programming With Ruby Episode 8,<br />
Hashes. 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 hashes are, how you can<br />
create them, access them, and iterate over them. Finally at the end I<br />
will show you some useful methods that hashes have.</p>
<p><strong>What Are Hashes?</strong></p>
<p>Hashes are like arrays, which you learned about in the previous<br />
episode. Except that they have no order, and instead of being accessed<br />
by an index number, they are accessed by what is called a key (which<br />
can be anything). That key points to a value, which is the actual data<br />
inside the hash</p>
<p>Arrays are used for lists of data, where hashes are used to relate<br />
data. I may have a hash where the keys are my friend&#8217;s names, and the<br />
values are their birthdays.</p>
<p><strong>Hash Creation</strong></p>
<p>Similarly to how arrays are created with square brackets, hashes are<br />
created with curly brackets:</p>
<pre class="brush: ruby; title: ; notranslate">
my_hash = {}
</pre>
<p>Items are defined like this:</p>
<pre class="brush: ruby; title: ; notranslate">
birthdays = {&quot;Amy&quot; =&gt; &quot;May&quot;, &quot;Dakota&quot; =&gt; &quot;January&quot;}
</pre>
<p>Each key-value pair are separated by a comma, and their relation is<br />
defined with =&gt;</p>
<p><strong>Accessing Hashes</strong></p>
<p>You can access hashes in almost the same way you access arrays, except<br />
by using the key value, instead of an index number:</p>
<pre class="brush: ruby; title: ; notranslate">
brithdays[&quot;Amy&quot;] #=&gt; May
</pre>
<p>You can define new keys and values:</p>
<pre class="brush: ruby; title: ; notranslate">
birthdays[&quot;Zack&quot;] = &quot;April&quot;
</pre>
<p><strong>Iterating Over Hashes</strong></p>
<p>Hashes have an each method like arrays do:</p>
<pre class="brush: ruby; title: ; notranslate">
my_hash = {&quot;cat&quot; =&gt; &quot;hat&quot;, &quot;dog&quot; =&gt; &quot;log&quot;}
my_hash.each do |pair|
	puts &quot;Key: &quot; + pair[0]
	puts &quot;Value: &quot; + pair[1]
end
#=&gt; Key: cat
#=&gt; Value: hat
#=&gt; Key: dog
#=&gt; Value: log
</pre>
<p>They also have each_key and each_value which let you iterate over each<br />
key or value in a similar way.</p>
<p><strong>Useful Hash Methods</strong></p>
<p><em>delete(key)</em> deletes a key-value pair<br />
<em>empty?</em> True or False if the hash is empty<br />
<em>keys</em> returns the keys<br />
<em>values</em> returns the values<br />
<em>size</em> how many key-value pairs there are</p>
<p>That wraps it up for this episode!</p>
<p>Please donate, or I will stop making these videos. There should be a<br />
link to donate 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, goodbye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/132/programming-with-ruby-episode-8-hashes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<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>
		<item>
		<title>How to Donate to Man With Code</title>
		<link>http://manwithcode.com/113/how-to-donate-to-man-with-code/</link>
		<comments>http://manwithcode.com/113/how-to-donate-to-man-with-code/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 07:24:51 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[donate]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=113</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/70QSRoqJW-Y&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/70QSRoqJW-Y&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/113/how-to-donate-to-man-with-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming With Ruby Episode 6, Strings</title>
		<link>http://manwithcode.com/101/programming-with-ruby-episode-6-strings/</link>
		<comments>http://manwithcode.com/101/programming-with-ruby-episode-6-strings/#comments</comments>
		<pubDate>Thu, 21 May 2009 09:17:42 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[strings]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=101</guid>
		<description><![CDATA[Covered in this episode: String Literals String Expressions String Methods Regular Expressions Getting User Input (gets) Transcript: Hello Everyone and Welcome to Programming With Ruby Episode 6, Strings. I&#8217;m Tyler, your presenter. This is brought to you by manwithcode.com In this episode I will be telling you what string literals are. I will show you [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/1ot2Wlsgsog&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/1ot2Wlsgsog&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><strong>Covered in this episode:</strong></p>
<ul>
<li>String Literals</li>
<li>String Expressions</li>
<li>String Methods</li>
<li>Regular Expressions</li>
<li>Getting User Input (gets)<strong> </strong><strong></strong></li>
</ul>
<p><strong>Transcript:</strong></p>
<p>Hello Everyone and Welcome to Programming With Ruby Episode 6,<br />
Strings. I&#8217;m Tyler, your presenter. This is brought to you by<br />
manwithcode.com</p>
<p>In this episode I will be telling you what string literals are. I will<br />
show you expressions you can use with strings, which are similar but<br />
still different than expressions with numbers. I will show you useful<br />
methods strings have. I will show you how to use regular<br />
expressions. Finally I will teach you how to get input from the<br />
user.</p>
<p>On to the Code!</p>
<p><strong>String Literals</strong></p>
<p>According to wikipedia, string literals are the representation of a<br />
string value within the source code of a computer program. For<br />
example:</p>
<pre class="brush: ruby; title: ; notranslate">
puts &quot;Hello World&quot; # Hello World is the string literal
</pre>
<p><strong>String Expressons</strong></p>
<p>The only string expressions are the plus and multiplication sign. The<br />
plus sign connects strings together, the multiplication sign repeats a<br />
string a certain number of times.<br />
Let me show you how it works:</p>
<pre class="brush: ruby; title: ; notranslate">
&quot;Hello &quot; + &quot;World!&quot; #=&gt; &quot;Hello World!&quot;
&quot;Hello &quot; * 3 #=&gt; &quot;Hello Hello Hello&quot;
</pre>
<p><strong>String Methods</strong></p>
<p>Here are some useful String methods:<br />
<em>empty?</em> tells you if you are dealing with an empty string<br />
<em>length</em> tells you how long a string is<br />
<em>each_char</em> lets you iterate over each character<br />
<em>capitalize</em> capitalizes the first character<br />
<em>upcase</em> makes all characters upper case<br />
<em>downcase</em> makes all characters lower case</p>
<p><strong>Regular Expressions</strong></p>
<p>Regular expressions are a way to match elements in other strings. It<br />
is easier to show you than to describe to you, so here we go!</p>
<p>The simplest is substitution:</p>
<pre class="brush: ruby; title: ; notranslate">
&quot;Hello World&quot;.sub(&quot;Hello&quot;, &quot;Goodbye&quot;)
#=&gt; &quot;Goodbye World&quot;
</pre>
<p>But if you have more than one hello:</p>
<pre class="brush: ruby; title: ; notranslate">
&quot;Hello Hello Hello&quot;.sub(&quot;Hello&quot;, &quot;Goodbye&quot;)
#=&gt; &quot;Goodbye Hello Hello&quot;
</pre>
<p>This happens because the sub method only replaces the first occurrence<br />
of &#8220;Hello&#8221;. The gsub method fixes this:</p>
<pre class="brush: ruby; title: ; notranslate">
&quot;Hello Hello Hello&quot;.gsub(&quot;Hello&quot;, &quot;Goodbye&quot;)
#=&gt; &quot;Goodbye Goodbye Goodbye&quot;
</pre>
<p>What if you want to manipulate parts of a string using regular<br />
expressions. The scan method is what you want!</p>
<pre class="brush: ruby; title: ; notranslate">
# /n means new line
&quot;Who are you&quot;.scan(/../) { |x| puts x }
#=&gt; Wh\no \nar\ne \nyo
# With no whitespace:
&quot;Who are you&quot;.scan(/\w\w/) { |x| puts x }
#=&gt; Wh/nar/nyo
</pre>
<p>Regular Expressions are a vast topic that I can&#8217;t completely cover<br />
here, so do a Google search to find out more.</p>
<p><strong>Getting User Input</strong></p>
<p>You can get user input with the &#8220;gets&#8221; method:</p>
<pre class="brush: ruby; title: ; notranslate">
a = gets
# The user inputs: I like pie
puts a #=&gt; &quot;I like pie&quot;
</pre>
<p>That wraps it up for todays episode.</p>
<p>Don&#8217;t forget to donate, the link is 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>Bye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/101/programming-with-ruby-episode-6-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
	</channel>
</rss>

