<?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; ruby</title>
	<atom:link href="http://manwithcode.com/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://manwithcode.com</link>
	<description>Teaching You, One Tutorial at a Time</description>
	<lastBuildDate>Thu, 09 Feb 2012 03:57:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>(Leave Feedback Here) Programming With Ruby Feedback</title>
		<link>http://manwithcode.com/235/leave-feedback-here-programming-with-ruby-feedback/</link>
		<comments>http://manwithcode.com/235/leave-feedback-here-programming-with-ruby-feedback/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 09:08:03 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[1000 comments]]></category>
		<category><![CDATA[feedback]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=235</guid>
		<description><![CDATA[Leave your feedback for the 1000 comments on the Programming With Ruby series]]></description>
			<content:encoded><![CDATA[<p>Leave your feedback for the  1000 comments on the Programming With Ruby series</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/235/leave-feedback-here-programming-with-ruby-feedback/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></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>2</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>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" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" 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/_jHM-3h-Bag&amp;hl=en&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed width="425" height="344" type="application/x-shockwave-flash" src="http://www.youtube.com/v/_jHM-3h-Bag&amp;hl=en&amp;fs=1&amp;" allowFullScreen="true" allowscriptaccess="always" allowfullscreen="true" /></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.collect 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>2</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</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>
		<item>
		<title>Programming With Ruby Episode 5, Numbers</title>
		<link>http://manwithcode.com/93/programming-with-ruby-episode-5-numbers/</link>
		<comments>http://manwithcode.com/93/programming-with-ruby-episode-5-numbers/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 07:42:41 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[numbers]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=93</guid>
		<description><![CDATA[Covered in This Episode Numbers Expressions Types of Numbers Constants (New type of variable!) Doing something a number of times Transcript Hello Everyone and Welcome to Programming With Ruby Episode 5, Numbers. Its sitll presented by me, Tyler. And brought to you by manwithcode.com In this episode I will be talking about numbers in Ruby. [...]]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/qdTM9mp0EsQ&#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/qdTM9mp0EsQ&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br />
<strong>Covered in This Episode</strong></p>
<ul>
<li>Numbers</li>
<li>Expressions</li>
<li>Types of Numbers</li>
<li>Constants (New type of variable!)</li>
<li>Doing something a number of times</li>
</ul>
<p><strong>Transcript</strong></p>
<p>Hello Everyone and Welcome to Programming With Ruby Episode 5,<br />
Numbers. Its sitll presented by me, Tyler. And brought to you by<br />
manwithcode.com</p>
<p>In this episode I will be talking about numbers in Ruby. I will go<br />
over expressions, the different types of numbers, I will introduce a<br />
new variable type called a constant, and will show you how to repeat<br />
an action a certain number of times in Ruby.</p>
<p>Lets get started!</p>
<p>Pop open you Command prompt or Terminal and start Interactive Ruby. If<br />
you have forgotten, just enter &#8216;irb&#8217;.</p>
<p>First item is expressions.</p>
<pre class="brush: ruby; title: ; notranslate">
2 + 2 #=&gt; 4
2 - 2 #=&gt; 0
3 * 3 #=&gt; 9
6 / 3 #=&gt; 2
2 ** 5 #=&gt; 5
</pre>
<p>expressions with variables work in the same way</p>
<pre class="brush: ruby; title: ; notranslate">
x = 5
5 * x #=&gt; 25
x ** 4 #=&gt; 625
</pre>
<p>If you want to do math on a variable and set the value of the variable<br />
to the result use:</p>
<pre class="brush: ruby; title: ; notranslate">
x = 5
x *= 2 #=&gt; x = 10
x -= 4 #=&gt; x = 6
x /= 6 #=&gt; x = 1
</pre>
<p>In Ruby there are 3 different types of numbers. Fixnum, which are<br />
32-bit numbers. Floats, which are numbers with a value after the<br />
decimal point. Bignums which are numbers larger than 32-bits.</p>
<pre class="brush: ruby; title: ; notranslate">
5.class #=&gt; Fixnum
0.421.class #=&gt; Float
999999999999 #=&gt; Bignum
</pre>
<p>In Ruby it is possible to separate up larger numbers to improve<br />
readability in the code. Simply place in underscores</p>
<pre class="brush: ruby; title: ; notranslate">
1_000_000 #=&gt; 1000000
</pre>
<p>Lets say you are writing some code and you need to do something a<br />
certain number of times. Use this code:</p>
<pre class="brush: ruby; title: ; notranslate">
2.times do |x|
puts x
end
#=&gt; 0
#=&gt; 1
</pre>
<p>That wraps it up for this episode. If you have any questions or<br />
comments, leave a comment in the comment box below. Or email me at<br />
tyler@manwithcode.com</p>
<p>Don&#8217;t forget to donate. The button is to the right of this video.</p>
<p>Thanks for watching. Goodbye</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/93/programming-with-ruby-episode-5-numbers/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<item>
		<title>Programming With Ruby Episode 4, Main Ruby Concepts</title>
		<link>http://manwithcode.com/84/programming-with-ruby-episode-4-main-ruby-concepts/</link>
		<comments>http://manwithcode.com/84/programming-with-ruby-episode-4-main-ruby-concepts/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 08:54:51 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[concepts]]></category>
		<category><![CDATA[main]]></category>
		<category><![CDATA[methods]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=84</guid>
		<description><![CDATA[Covered In This Episode: Basic Variables Basic Methods Basic Classes Interactive Ruby (irb) Code: Transcript: Hello everybody and welcome to Programming With Ruby Episode 4, Main Ruby Concepts. Covered in this episode. We&#8217;ll be playing with interactive ruby (also called irb). I will teach you about variables, basic methods, and classes in Ruby. Lets get [...]]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/8W7MJrAzeWw&#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/8W7MJrAzeWw&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br />
<strong>Covered In This Episode:</strong></p>
<ul>
<li>Basic Variables</li>
<li>Basic Methods</li>
<li>Basic Classes</li>
<li>Interactive Ruby (irb)</li>
</ul>
<p><strong>Code:</strong></p>
<pre class="brush: ruby; title: ; notranslate">
# Define the class Greeter
class Greeter
	# Define the method hello
	# This method greets the
	# user
	def hello(name)
		puts &quot;Hello &quot; + name
	end # End of the method hello
end # End of the class Greeter

Greeter.new.hello(&quot;Tyler&quot;)
</pre>
<p><strong><br />
</strong></p>
<p><strong>Transcript:</strong></p>
<p>Hello everybody and welcome to Programming With Ruby Episode 4, Main<br />
Ruby Concepts.</p>
<p>Covered in this episode. We&#8217;ll be playing with interactive ruby (also</p>
<p>called irb). I will teach you about variables, basic methods, and</p>
<p>classes in Ruby. Lets get started!</p>
<p><strong>Basics Description</strong></p>
<p>Ruby is an object oriented programming language. object oriented<br />
languages use objects. Ruby goes beyond most other object oriented<br />
languages, because in Ruby, everything is an object. (I&#8217;ll show you<br />
exactly what that means in a few minutes)</p>
<p>Object oriented programming sort of models real life. Look around you,<br />
everything around you is an object. Your computer, your desk, books,<br />
the moon, and people are all objects.</p>
<p>In programming, all objects have properties called variables. These<br />
could be the color of the object, the weight, size, or any other kind<br />
of property.</p>
<p>Objects also have methods (which are sometimes called functions). A<br />
camera object would have a method to take pictures. A car would have a<br />
method to drive. A printer would have a method to print.</p>
<p>As well as making code easier to understand, you will also continue to<br />
appreciate other benefits of object oriented programming further on in<br />
your programming career.</p>
<p><strong>Example</strong></p>
<p>I have written a very basic Ruby program. This is about what most<br />
programs look like, just a lot simpler. Let&#8217;s break it down line by<br />
line.</p>
<p>Everything followed by a hash mark (#), is ignored by Ruby. These are<br />
called comments. In these comments you can describe what your code is<br />
doing, make notes to yourself, and other such things.</p>
<p>The first line says &#8220;class Greeter&#8221;. This line tells Ruby that we are<br />
now defining a class named &#8220;Greeter&#8221;. Please remember that all classes<br />
in Ruby start with a capital letter!</p>
<p>The next line says &#8220;def hello(name)&#8221;. This line means we are defining<br />
a function (def), named &#8220;hello&#8221;, that takes the parameter &#8220;name&#8221;.</p>
<p>The following line is a little trickier. &#8216;puts &#8220;Hello &#8221; +<br />
name&#8217;. &#8220;puts&#8221; means &#8220;put string&#8221;. our string is &#8220;Hello &#8221; + name. Now<br />
you&#8217;re probably wondering what the &#8220;+ name&#8221; is for. We&#8217;re aren&#8217;t doing<br />
math on strings, but we are connecting the variable &#8220;name&#8221; to our other<br />
string &#8220;Hello &#8220;.</p>
<p>The next two lines have the keyword &#8220;end&#8221;. The first end means we are<br />
done defining the function &#8220;hello&#8221;. The second &#8220;end&#8221; means we are done<br />
defining the class &#8220;Greeter&#8221;.</p>
<p>Below where the class &#8220;Greeter&#8221; ends we have the line &#8216;myname =<br />
&#8220;Tyler&#8221;&#8216;. This means are creating the variable myname and placing<br />
&#8220;Tyler&#8221; inside of it.</p>
<p>Next is, the line &#8220;person = Greeter.new&#8221;. This means we are<br />
instantiating a new greeter object named person.</p>
<p>Finally we have the line &#8220;person.hello(myname)&#8221;. This calls the<br />
person object&#8217;s method &#8220;hello&#8221; and passes the variable &#8220;myname&#8221; as an<br />
argument.</p>
<p>Now lets run the program. If you remember, to run a program you open<br />
Terminal or Command Prompt, change directories into where you saved<br />
your program and type &#8220;ruby programname.rb&#8221;. In my case I will type<br />
&#8220;ruby episode4.rb&#8221;.<br />
And there you have it, it says &#8220;Hello Tyler&#8221;</p>
<p>The code in this example will be available in the YouTube video<br />
description, and below this video on manwithcode.com</p>
<p><strong>Example 2</strong><br />
Back to the code. This code is actually a little longer<br />
than it has to be. I did this so things would hopefully make more<br />
sense. In reality we can change the last three lines to<br />
&#8216;Greeter.new.hello(&#8220;Tyler&#8221;)&#8217;</p>
<p>We can do this because in Ruby, everything is an expression. Here&#8217;s how<br />
it breaks down. &#8220;Greeter.new&#8221; creates a greeter object. &#8220;.hello&#8221; calls<br />
the method &#8220;hello&#8221; on that new object. And then we pass in the string<br />
&#8220;Tyler&#8221; as an parameter.</p>
<p>Ruby has many other tricks like this to make your code shorter. Some<br />
have disadvantages and others do not. One of the most important<br />
disadvantages can be clarity or readability. You want your code to be<br />
as easy to understand as possible.</p>
<p><strong>irb</strong><br />
Interactive Ruby (or irb for short). irb makes it very easy to<br />
quickly test out code, find out if/how something works, do basic math,<br />
and write throwaway code you will only use once.</p>
<p>To open irb, open up your Command Prompt or Terminal and enter<br />
irb. Alternatively, if you are on Windows, go into All Programs and<br />
under Ruby will be a program name fxri which is an equivalent to irb.</p>
<p>In irb you can do basic math:</p>
<pre class="brush: ruby; title: ; notranslate">
2 + 2 #=&gt; 4
2**6 #=&gt; 64
2 * 5 #=&gt; 10
</pre>
<p>We can write any valid Ruby code. So we could write the greet method again.</p>
<pre class="brush: ruby; title: ; notranslate">
def greet(name)
    puts &quot;Hello &quot; + name
end
</pre>
<p>And then call it:</p>
<pre class="brush: ruby; title: ; notranslate">
greet(&quot;Tyler&quot;)
</pre>
<p>Remember earlier I said everything in Ruby was an object? I&#8217;ll show<br />
you what I mean. if you type in the name of an object and call the<br />
class method it will tell you its class.</p>
<pre class="brush: ruby; title: ; notranslate">
0.class #=&gt; Fixnum
&quot;Hello&quot;.class #=&gt;; String
String.class #=&gt; Class
</pre>
<p>I encourage you to play around with irb for a little while, try<br />
writing your own methods, and have some fun with it.</p>
<p><strong>End</strong><br />
This brings us to the end of this episode, I hope it helped<br />
you.  If you need any help, have questions or comments, leave a<br />
comment below or contact me at tyler@manwithcode.com</p>
<p>Don&#8217;t forget to donate! There is a donation link to the right of this<br />
video. On YouTube its in the description box. On my website, it is to<br />
the right of the video.</p>
<p>Thanks for watching! Bye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/84/programming-with-ruby-episode-4-main-ruby-concepts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<item>
		<title>Programming With Ruby Episode 3, Getting Help/Tools</title>
		<link>http://manwithcode.com/74/programming-with-ruby-episode-3-getting-help-tools/</link>
		<comments>http://manwithcode.com/74/programming-with-ruby-episode-3-getting-help-tools/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 09:21:07 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=74</guid>
		<description><![CDATA[Covered in this episode: How to get help Google Ruby&#8217;s Documentation Forums/Mailing Lists Blogs on Ruby Text Editors Integrated Development Environments (IDEs) Links: Ruby-Lang: http://www.ruby-lang.org Ruby-Doc:  http://www.ruby-doc.org/ Forums: http://www.ruby-forum.com/ http://www.rubyforums.com/ Text Editors: Notepad++ http://notepad-plus.sourceforge.net/uk/site.htm SciTE http://www.scintilla.org/SciTE.html jEdit http://www.jedit.org/ Text Mate http://macromates.com/ IDEs Netbeans http://www.netbeans.org/ Aptana Rad Rails http://www.aptana.com/ FreeRIDE http://rubyforge.org/projects/freeride/ Geany http://www.geany.org/ More&#8230; http://rubyforge.org/softwaremap/trove_list.php?form_cat=65 Transcript [...]]]></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/xwzalx7OcA4&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/xwzalx7OcA4&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><strong>Covered in this episode:</strong></p>
<ul>
<li>How to get help</li>
<li>Google</li>
<li>Ruby&#8217;s Documentation</li>
<li>Forums/Mailing Lists</li>
<li>Blogs on Ruby</li>
<li>Text Editors</li>
<li>Integrated Development Environments (IDEs)</li>
</ul>
<p><strong>Links:</strong></p>
<p>Ruby-Lang: <a title="Ruby Lang" href="http://www.ruby-lang.org" target="_blank">http://www.ruby-lang.org</a><br />
Ruby-Doc:  <a title="Ruby Documentation" href="http://www.ruby-doc.org/" target="_blank">http://www.ruby-doc.org/</a></p>
<p><strong>Forums:</strong></p>
<p><a title="Ruby Forum" href="http://www.ruby-forum.com/" target="_blank">http://www.ruby-forum.com/</a><br />
<a title="Ruby Forums" href="http://www.rubyforums.com/" target="_blank">http://www.rubyforums.com/</a></p>
<p><strong>Text Editors:</strong><br />
Notepad++ <a title="Notepad plus plus" href="http://notepad-plus.sourceforge.net/uk/site.htm" target="_blank">http://notepad-plus.sourceforge.net/uk/site.htm</a><br />
SciTE <a title="SciTE" href="http://www.scintilla.org/SciTE.html" target="_blank">http://www.scintilla.org/SciTE.html</a><br />
jEdit <a title="jedit" href="http://www.jedit.org/" target="_blank">http://www.jedit.org/</a><br />
Text Mate <a title="Text Mate" href="http://macromates.com/" target="_blank">http://macromates.com/</a></p>
<p><strong>IDEs</strong><br />
Netbeans <a title="Netbeans IDE" href="http://www.netbeans.org/" target="_blank">http://www.netbeans.org/</a><br />
Aptana Rad Rails <a title="Aptana Rad Rails" href="http://www.aptana.com/" target="_blank">http://www.aptana.com/</a><br />
FreeRIDE <a title="freeRIDE" href="http://rubyforge.org/projects/freeride/" target="_blank">http://rubyforge.org/projects/freeride/</a><br />
Geany <a title="Geany IDE" href="http://www.geany.org/" target="_blank">http://www.geany.org/</a><br />
More&#8230;<a title="More IDEs on Rubyforge" href="http://rubyforge.org/softwaremap/trove_list.php?form_cat=65" target="_blank"> http://rubyforge.org/softwaremap/trove_list.php?form_cat=65</a></p>
<p><strong>Transcript</strong></p>
<p>Hello Everybody! And Welcome to Programming with Ruby Episode 3, Getting Help<br />
and Tools. I&#8217;m your presenter, Tyler. This video is brought to you by<br />
manwithcode.com</p>
<p>Covered in this Episode.<br />
I&#8217;ll be going over how to get help.<br />
If you ever get stuck while using Ruby you&#8217;re first stop should be Google,<br />
to some this may sound obvious, but some people still don&#8217;t use Google.<br />
Your next stop would be Ruby&#8217;s Documentation.<br />
Then I will be showing you forums and mailing lists where you can ask for help<br />
or help others.<br />
Also I will be showing you some blogs by Ruby Developers.</p>
<p>On the tools side, I will be showing you some good Text Editors, and a few<br />
IDEs (or Integrated Development Environments).</p>
<p>Just as a side note, I will be showing many websites today, but don&#8217;t worry,<br />
all links are in the description</p>
<p>Lets Get Started!</p>
<p>Out first stop will be Google. Lets say I wanted to learn about Ruby Lambdas<br />
just type in &#8220;ruby lamdas&#8221; and you get a list of relavant web pages. I&#8217;ll<br />
pick the first link, and here is some information on how to use lambdas.</p>
<p>If Google can&#8217;t help you, lets look at the official Ruby Documentation.<br />
This is ruby-doc.org. It has some articles and tutorials on Ruby. But what<br />
we are interested in is the part that says &#8220;Core API&#8221; we are using the<br />
1.8 version of Ruby, so we will visit the 1.8.6 core link<br />
and here is the documentation for Ruby! lets say I wanted to look for lambdas<br />
again, I&#8217;ll hit CTRL-F for the browsers find funtion, and type in &#8220;lambda&#8221; and<br />
here is the information I want, I&#8217;ll click the link, and there is the<br />
documentation!</p>
<p>Okay lets say that a Google search and a look through the documentation doesn&#8217;t<br />
help you with your problem. What do you do? You ask a person, of course! This<br />
is where the forums come in.</p>
<p>There are two forums that I like, there is ruby-forum.com<br />
And rubyforums.com<br />
both of which you can post on and will hopefully get answers</p>
<p>For general tips and news about Ruby, you may be interested in some blogs about<br />
Ruby. To find some, lets go to ruby-lang.org<br />
click on the community link.<br />
scroll down, and click the &#8220;weblogs about ruby&#8221; link<br />
and here there are some blogs, and aggregators listed</p>
<p>So hopefully if you have a problem all these resources should be able to help<br />
you. Now we are going to move onto tools. First stop Text Editors.</p>
<p>There are a few good text editors available, so I will just highlight a few.<br />
If any of these look interesting, remember that all links are in the description.<br />
First is Windows only text editor notepad++, the editor I use on Windows<br />
Then is SciTE, a scintilla based editor<br />
Jedit is a popular text editor that is written in Java<br />
Text mate is a very popular text editor for the Macintosh that costs $55<br />
For Linux there are editors like gEdit and Kate which have some of the features<br />
of the editors mentioned above.</p>
<p>Even if you like your featureless plain text editor like notepad, features the<br />
previously mentioned editors have make writing code much easier, and I recommend<br />
you get one.</p>
<p>First we have netbeans, which is my IDE of choice. Even though it was originally<br />
for Java, it works very well with Ruby<br />
Next is Aptana rad rails, an IDE which many people like, but was too buggy on my<br />
computer, it is especially useful if you are using Ruby on Rails<br />
freeRIDE is a popular editor for ruby<br />
Geany is a GTK based editor for Linux that works with many different languages</p>
<p>These are all very good editors, but because you are currently learning I would<br />
just recommend a text editor for now, when you start developing larger projects<br />
an IDE can be very useful.</p>
<p>This brings us to the end of this episode, I hope it helped you.<br />
If you need any help, have questions or comments, leave a comment below or<br />
contact me at tyler@manwithcode.com</p>
<p>Hey! before you go, you may have realized that I am making these videos for free<br />
if they have helped you at all please donate. If you viewing this on Youtube there is a<br />
donation link to the right in the description box. If you are on my site there is<br />
a donation button to the right</p>
<p>Thanks for watching! Bye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/74/programming-with-ruby-episode-3-getting-help-tools/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<item>
		<title>Programming With Ruby Episode 2, Getting Started</title>
		<link>http://manwithcode.com/55/programming-with-ruby-episode-2-getting-started/</link>
		<comments>http://manwithcode.com/55/programming-with-ruby-episode-2-getting-started/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 04:03:30 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[hello world]]></category>
		<category><![CDATA[installing]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=55</guid>
		<description><![CDATA[Covered in this episode: Installing Ruby What you will need Hello World! program Transcript Hello everybody and welcome to Programming with Ruby Episode 2 &#8211; Getting Started. I&#8217;m the presenter, as always, Tyler. This is brought to you by manwithcode.com. This is ruby-lang.org. Go to the downloads section. There are a bunch of links here. [...]]]></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/YLGQyKyWnXM&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/YLGQyKyWnXM&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
<strong>Covered in this episode:</strong></p>
<ul>
<li>Installing Ruby</li>
<li>What you will need</li>
<li>Hello World! program</li>
</ul>
<p><strong>Transcript</strong></p>
<p>Hello everybody and welcome to Programming with Ruby Episode 2 &#8211; Getting Started. I&#8217;m the presenter, as always, Tyler. This is brought to you by manwithcode.com.</p>
<p>This is ruby-lang.org. Go to the downloads section. There are a bunch of links here. If you are on Windows, go to the Ruby One-Click Installer. It is a standard installer, like any other Windows program.</p>
<p>If you are on a Debian variant of Linux (such as Ubuntu). The line:<br />
sudo apt-get install ruby irb rdoc<br />
will get you what you need</p>
<p>If you are on mac OSX, you can install ruby with mac ports via the command:<br />
port install ruby<br />
alternatively you can go to the ruby OSX one click installer (http://rubyosx.rubyforge.org/), be sure to the installer for version 1.8.7 not 1.9.1</p>
<p>If you are compiling from source, compile 1.8.7 NOT 1.9.1</p>
<p>To get started you will need a text editor, like Notepad. It needs to be plain text editor, we don&#8217;t want any of the formatting that programs like Word put on there.</p>
<p>My editor of choice is gEdit, which comes with the GNOME desktop on Linux.</p>
<p>Alternatively you can use an IDE, like Netbeans or Geany.</p>
<p>Open up your text editor, and type in:</p>
<pre class="brush: ruby; title: ; notranslate">
puts &quot;Hello World!&quot;
</pre>
<p>save that to your desktop as hello.rb</p>
<p>There are two ways of running this. If you are on Windows, go to where you saved it and double click on it.</p>
<p>Or you can open up the Command Prompt/Terminal. Change directories to where you saved the files and type in:<br />
ruby hello.rb</p>
<p>Questions or Comments<br />
Leave a comment on this page<br />
or email me at tyler@manwithcode.com</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/55/programming-with-ruby-episode-2-getting-started/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
		<item>
		<title>Programming With Ruby Episode 1, Introduction</title>
		<link>http://manwithcode.com/31/programming-with-ruby-episode-1-introduction/</link>
		<comments>http://manwithcode.com/31/programming-with-ruby-episode-1-introduction/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 02:30:28 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[introduction]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=31</guid>
		<description><![CDATA[Covered in this episode: What this series is about A Short History of programming languages What is Ruby (and who makes it) What is Ruby used for Who am I Why am I teaching this Transcript Hello everybody and welcome to Programming with Ruby Episode 1, Introduction What this series is about By the end [...]]]></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/p3jyESVlA2k&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/p3jyESVlA2k&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
<strong>Covered in this episode:</strong></p>
<ul>
<li>What this series is about</li>
<li>A Short History of programming languages</li>
<li>What is Ruby (and who makes it)</li>
<li>What is Ruby used for</li>
<li>Who am I</li>
<li>Why am I teaching this</li>
</ul>
<p><strong>Transcript</strong></p>
<p>Hello everybody and welcome to Programming with Ruby Episode 1, Introduction</p>
<p><strong>What this series is about </strong><br />
By the end of this series you should be able to effectively use the programming language, Ruby</p>
<p><strong>Short History of Programming Languages </strong><br />
when it all first started out, everything was just 1s and 0s, it was hard to use, and difficult to debug<br />
then it got a little better when assembly came along. You had words like MOV that translated into the corresponding 1s and 0s. compiled by and assembler<br />
then came COLBOL and FORTRAN<br />
then C, which was better, but still sucked<br />
then C++ which brought object orientation to the world<br />
then Python and Ruby. they are both object oriented and very easy to use.</p>
<p><strong>What is Ruby? </strong><br />
A programming language, that supports many different kinds of programming paradigms, and is fully object oriented<br />
Ruby was created by Yuukihiro &#8220;Matz&#8221; Matsumoto<br />
Matz designed Ruby to be natural, not simple. I think he achieved that.</p>
<p><strong>What is Ruby Used For?</strong><br />
Ruby is used a lot for Web Applications<br />
Computer Administration<br />
Task Automation<br />
Game Programming<br />
And almost anything else<br />
The only thing you might want to stay away from are things that are computationally expensive, like image processing.</p>
<p><strong>Who am I? </strong><br />
I am Tyler J Church<br />
I run the sites Man With Code (manwithcode.com) and ruby game dev (rubygamedev.wordpress.com)</p>
<p><strong>Why am I Teaching This?</strong><br />
It is the tutorial I never had. I was look for something like this when I started learning Ruby. I didn&#8217;t want to read a bunch, I wanted to watch videos, but nothing like that existed<br />
I think video is the best way to learn<br />
I want to give back to the community. That brought me Ruby, that helped me learn. Thank You!</p>
<p><strong>Questions or Comments </strong><br />
Leave a comment on this page<br />
or email me at tyler@manwithcode.com</p>
<p>Thanks for reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/31/programming-with-ruby-episode-1-introduction/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
	</channel>
</rss>

