<?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/"
	>

<channel>
	<title>RubyLearning Blog &#187; Victor Goff</title>
	<atom:link href="http://rubylearning.com/blog/author/victorgoff/feed/" rel="self" type="application/rss+xml" />
	<link>http://rubylearning.com/blog</link>
	<description>Helping Ruby Programmers become Awesome</description>
	<lastBuildDate>Tue, 21 May 2013 02:40:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Book Review: Exploring Everyday Things with R and Ruby</title>
		<link>http://rubylearning.com/blog/2012/07/09/book-review-exploring-everyday-things-with-r-and-ruby/</link>
		<comments>http://rubylearning.com/blog/2012/07/09/book-review-exploring-everyday-things-with-r-and-ruby/#comments</comments>
		<pubDate>Mon, 09 Jul 2012 03:15:00 +0000</pubDate>
		<dc:creator>Victor Goff</dc:creator>
				<category><![CDATA[Book Promotions]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Book review]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[R and Ruby]]></category>
		<category><![CDATA[Sau Sheong Chang]]></category>

		<guid isPermaLink="false">http://rubylearning.com/blog/?p=6609</guid>
		<description><![CDATA[Send to Kindle A book review of Exploring Everyday Things with R and Ruby.Review by: RubyLearning&#8217;s mentor Victor Goff.Book author: Sau Sheong Chang. Publisher: O&#8217;Reilly Media. I got the opportunity to review Exploring Everyday Things with R and Ruby by Sau Sheong Chang and published by O&#8217;Reilly Media1 This book, as expected, talks about R [...]<p><a href="http://www.launchbit.com/az/113-209/"><img width="468" height="60" src="http://www.launchbit.com/az-images/113-209/" /></a><br />
<small>(Powered by <a href="http://www.launchbit.com/lb/113-209/">LaunchBit</a>)</small></p>
]]></description>
				<content:encoded><![CDATA[<div class='kindleWidget kindleLight' ><img src="http://rubylearning.com/blog/wp-content/plugins/send-to-kindle/media/black-25.png" /><span>Send to Kindle</span></div><p></p>
<div class="topsy_widget_data topsy_theme_brick-red" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Frubylearning.com%252Fblog%252F2012%252F07%252F09%252Fbook-review-exploring-everyday-things-with-r-and-ruby%252F%22%2C%20%22shorturl%22%3A%20%22http%3A%2F%2Fbit.ly%2FNez1L9%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Book%20Review%3A%20Exploring%20Everyday%20Things%20with%20R%20and%20Ruby%22%20%7D);"></div>
<div>
<p class="update">A book review of <strong>Exploring Everyday Things with R and Ruby</strong>.<br />Review by: RubyLearning&#8217;s mentor Victor Goff.<br />Book author: Sau Sheong Chang.<br /> Publisher: O&#8217;Reilly Media.</p>
<p class="block"><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright" src="http://rubylearning.com/images/cat.gif" alt="Exploring Everyday Things with R and Ruby" /> <span class="drop_cap">I</span> got the opportunity to review <a href="http://shop.oreilly.com/product/0636920022626.do">Exploring Everyday Things with R and Ruby</a> by Sau Sheong Chang and published by O&#8217;Reilly Media<sup class='footnote'><a href='#fn-6609-1' id='fnref-6609-1'>1</a></sup></p>
<p>This book, as expected, talks about R and Ruby. The first chapters cover Ruby at an introductory level.</p>
<p>In the first chapter, after showing how you can install Ruby and an introduction to the basics of Ruby, he also provides &#8220;a quick introduction to Shoes, a simple but powerful UI toolkit for Ruby&#8221;<sup class='footnote'><a href='#fn-6609-2' id='fnref-6609-2'>2</a></sup>, with installation suggestions and sample code.</p>
<p>His introduction to Ruby covers the basics and is just a bit more than enough to understand the code in the rest of his book. I think he did a really good job of that. The second part of the first chapter, covering Shoes, explains Shoes in a nutshell rather well, I think. You will get to use Shoes in later chapters.</p>
<p>He then goes on to introduce R, which I had not used before. He covers in a way that was fairly straightforward to install and get running. Within a few moments, I had R installed and the &#8216;normal&#8217; graphical tools up and running and was able to run some sample code, and even had graphs floating around my screen based on data that I created from the samples.</p>
<p>Shortly after that, I had R code being created in my favorite text editor, and executing code right from there.</p>
<p>His introduction to the language is fairly quick, but again, just a bit more than enough to get you going.</p>
<p>He also covers some statistical transformation examples to change the statistical data into plottable information. That is a good thing, because throughout the book, you will be needing to recognize this in the examples, and will have fun producing your own graphical representations of data you get.</p>
<p>And all that is enough to get you started creating models to solve real world problems.</p>
<p>For example, do you need to convince your boss that you need more restrooms available for the people in your office? You can provide some simulations and reports and graphs (the boss likes graphs, right?) to support your argument, or will it support his assertion that what you have is just the right amount?</p>
<p>This gets to the fun part. Have you ever wondered how to mine data from your own e-mail? To find trends of when you send mail, or who you communicate with most? Finding the most often used words and the trending themes in your communications? You are in luck. He will take you through the Enron Saga to lightly touch on analyzing that e-mail data<sup class='footnote'><a href='#fn-6609-3' id='fnref-6609-3'>3</a></sup>, but easily apply it to your own IMAP e-mail accounts.</p>
<p>How about biometrics, recording your own heartbeat through a home-made electronic stethoscope? Yes, you will be able to do this, and take measurements, and analyze them graphically. Combine that with pulse oximetry with your webcam and you might have just enough evidence to convince your boss that your cubicle is suffocating you.</p>
<p>That sounds fun enough, but it will involve analyzing sound files and video files to get the readings and measurements that you want to produce in a graphical chart. That makes it fun to the nth power, right?</p>
<p>Well, what can be more fun than Boid&#8217;s&#8230; and boid <b>is</b> the woid<sup class='footnote'><a href='#fn-6609-4' id='fnref-6609-4'>4</a></sup> in this next chapter. Using Ruby Shoes you will explore the flocking of birds, you will write a simulation and are encouraged to continue playing on.</p>
<p>What follows is an extension of the Boids and introduces the mortality and procreation of the boids, which were prior to this immortals in a veritable utopia. Life simulated and analyzed.</p>
<p>Overall, I really enjoyed this book, it was easy to read, had some math in it, of course, but nothing that requires advanced math. And the topics were fun to work through. And there is plenty of room to experiment and explore after finishing the chapters.</p>
<p>Like this review?</p>
<p class="alert">&#8220;Book Review: Exploring Everyday Things with R and Ruby&#8221; &#8211; <a href="https://twitter.com/intent/tweet?text=Book+Review%3A+Exploring+Everyday+Things+with+R+and+Ruby+http%3A%2F%2Fbit.ly%2FNez21o" title="Book Review: Exploring Everyday Things with R and Ruby">Click to Tweet</a></p>
</div>
<p>Technorati Tags: <a href="http://technorati.com/tag/Book+review" rel="tag">Book review</a>, <a href="http://technorati.com/tag/Ruby" rel="tag"> Ruby</a>, <a href="http://technorati.com/tag/Programming" rel="tag"> Programming</a>, <a href="http://technorati.com/tag/R+and+Ruby" rel="tag"> R and Ruby</a>, <a href="http://technorati.com/tag/Sau+Sheong+Chang" rel="tag"> Sau Sheong Chang</a></p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-6609-1'>&#8220;Exploring Everyday Things with R and Ruby &#8211; O&#8217;Reilly Media.&#8221; 2012. 6 Jul. 2012 <a href="http://shop.oreilly.com/product/0636920022626.do">http://shop.oreilly.com/product/0636920022626.do</a>. <span class='footnotereverse'><a href='#fnref-6609-1'>&#8617;</a></span></li>
<li id='fn-6609-2'>&#8220;Exploring Everyday Things with R and Ruby &gt; 1. The Hat and the &#8230;&#8221; 2012. 6 Jul. 2012 <a href="http://my.safaribooksonline.com/book/-/9781449342203/1dot-the-hat-and-the-whip/id2776202">http://my.safaribooksonline.com/book/-/9781449342203/1dot-the-hat-and-the-whip/id2776202</a> <span class='footnotereverse'><a href='#fnref-6609-2'>&#8617;</a></span></li>
<li id='fn-6609-3'>&#8220;Enron Email Dataset.&#8221; 2004. 6 Jul. 2012 <a href="http://www.cs.cmu.edu/~enron/">http://www.cs.cmu.edu/~enron/</a> <span class='footnotereverse'><a href='#fnref-6609-3'>&#8617;</a></span></li>
<li id='fn-6609-4'>Did you see what I did there? &#8220;The Trashman &#8211; The surfin bird &#8211; YouTube.&#8221; 2007. 6 Jul. 2012 <a href="http://www.youtube.com/watch?v=QXLqMB6vBic">http://www.youtube.com/watch?v=QXLqMB6vBic</a> <span class='footnotereverse'><a href='#fnref-6609-4'>&#8617;</a></span></li>
</ol>
</div>
Posted by <b>Victor Goff</b><p><a href="http://www.launchbit.com/az/113-209/"><img width="468" height="60" src="http://www.launchbit.com/az-images/113-209/" /></a><br />
<small>(Powered by <a href="http://www.launchbit.com/lb/113-209/">LaunchBit</a>)</small></p>

]]></content:encoded>
			<wfw:commentRss>http://rubylearning.com/blog/2012/07/09/book-review-exploring-everyday-things-with-r-and-ruby/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Do you know Ruby Doctest?</title>
		<link>http://rubylearning.com/blog/2011/10/05/do-you-know-ruby-doctest/</link>
		<comments>http://rubylearning.com/blog/2011/10/05/do-you-know-ruby-doctest/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 03:17:08 +0000</pubDate>
		<dc:creator>Victor Goff</dc:creator>
				<category><![CDATA[Beginners]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Ruby DocTest]]></category>
		<category><![CDATA[ruby programming]]></category>

		<guid isPermaLink="false">http://rubylearning.com/blog/?p=6144</guid>
		<description><![CDATA[Send to Kindle Do you know Ruby Doctest? This guest post is by Victor Goff, who enjoys mentoring Ruby at RubyLearning.org since 2008. You can reach him on IRC Chat #rubylearning on freenode.net. He also blogs occasionally at http://vgoff.posterous.com. Rubydoctest is a gem that we will be installing. The purpose of the gem is simply [...]<p><a href="http://www.launchbit.com/az/113-209/"><img width="468" height="60" src="http://www.launchbit.com/az-images/113-209/" /></a><br />
<small>(Powered by <a href="http://www.launchbit.com/lb/113-209/">LaunchBit</a>)</small></p>
]]></description>
				<content:encoded><![CDATA[<div class='kindleWidget kindleLight' ><img src="http://rubylearning.com/blog/wp-content/plugins/send-to-kindle/media/black-25.png" /><span>Send to Kindle</span></div><p></p>
<div class="topsy_widget_data topsy_theme_brick-red" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Frubylearning.com%252Fblog%252F2011%252F10%252F05%252Fdo-you-know-ruby-doctest%252F%22%2C%20%22shorturl%22%3A%20%22http%3A%2F%2Fbit.ly%2FngEQqQ%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Do%20you%20know%20Ruby%20Doctest%3F%22%20%7D);"></div>
<div>
<h3>Do you know Ruby Doctest?</h3>
<p class="update">This guest post is by <strong><a title="Victor Goff" href="http://gplus.to/vhgiii">Victor Goff</a></strong>, who enjoys mentoring Ruby at <a href="http://rubylearning.org/">RubyLearning.org</a> since 2008. You can reach him on IRC Chat #rubylearning on <a href="http://webchat.freenode.net/?channels=rubylearning.org&amp;uio=Mj10cnVlJjQ9dHJ1ZSY5PXRydWUmMTE9MjU2d9">freenode.net</a>. He also blogs occasionally at <a href="http://vgoff.posterous.com/">http://vgoff.posterous.com</a>.</p>
<p class="block"><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright" src="http://rubylearning.com/blog/wp-content/uploads/vg.jpg" alt="Victor Goff III" /> <span class="drop_cap">R</span>ubydoctest is a gem that we will be installing. The purpose of the gem is simply to provide a way to document our programs using IRB sessions, resulting in a way to provide usage examples as well as knowing when an expected use fails because of some update or changes to our program or environment.</p>
<h4>Installing Ruby DocTest</h4>
<p>Rubydoctest can be installed by doing the following from the command line:</p>
<pre>$ gem install rubydoctest</pre>
<p>If you are running Windows or using RVM the above should work (pending network/internet connectivity) but you may need to use <code>sudo</code> to install depending on your set up.</p>
<h4>The parts of Ruby DocTest</h4>
<p>Rubydoctest information can be contained within a comment or a comment block.</p>
<p>Let&#8217;s start by creating a file <code>hello.rb</code>:</p>
<pre>def hello name
  "Hello " + name
end
=begin # This is the beginning of a comment block
doctest: hello " World" will return "Hello World"
&gt;&gt; hello "World"
=&gt; "Hello World"
=end</pre>
<p>We have our trusty method called <code>hello</code>, but we have added a comment block with doctest information inside. Other than the <code>doctest:</code> directive, it should remind you of an IRB session.</p>
<p>The <code>doctest:</code> directive is the human readable title of the test. If this isn&#8217;t supplied you would end up seeing &#8216;default&#8217; as the title.</p>
<p>To use rubydoctest:</p>
<pre>USAGE: rubydoctest [options] 

  rubydoctest parses Ruby files (.rb) or DocTest files (.doctest) for irb-style
  sessions in comments, and runs the commented sessions as tests.

  Options:
    Output Format:
      --html  - output in HTML format
      --plain - force output in plain text (no Ansi colors)

    Debug:
      --ignore-interactive - do not heed !!! special directives
      --trace     - turn backtrace on to debug Ruby DocTest
      --debugger  - include ruby-debug library / gem</pre>
<p>Let&#8217;s go ahead and run the following command to see what happens here:</p>
<pre>rubydoctest hello.rb
=== Testing 'hello.rb'...
 OK  | hello "World" will return "Hello World"
1 comparisons, 1 doctests, 0 failures, 0 errors</pre>
<p>As you can see, we get passing tests. And if this were above the method definition it may even be collected during ri and rdoc generation (this process is outside the scope of this article.)</p>
<h4>Refactoring with RubyDoctest</h4>
<p>Once we have a simple test in place, and that test is passing, we can refactor it, with confidence that the method still passes.</p>
<p>I noticed that I used &#8220;String&#8221; + variable in this method, but realized that it may read a little better (and create only one object) if I use string interpolation:</p>
<pre>def hello name
  "Hello #{name}"
end</pre>
<p>Which I think should pass the test, but just for good measure, we want to actually test it:</p>
<pre>rubydoctest hello.rb
=== Testing 'hello.rb'...
 OK  | hello "World" will return "Hello World"
1 comparisons, 1 doctests, 0 failures, 0 errors</pre>
<p>And as we can see, it passes.</p>
<p>Next, we will fully develop our <code>hello</code> method so that it has some nice features.</p>
<h4>Using RubyDoctest in a TDD manner</h4>
<p>We will be starting our <code>hello</code> method over from scratch. Going through the full life cycle of a small method, and testing along the way. It will be conversational, and demonstrative, so that you can follow along as we go.</p>
<h5>Starting with an idea</h5>
<p>It all starts with an idea: I would like a <code>hello</code> method that will simply state &#8220;Hello World!&#8221; In order to make this happen, and have the documentation and the tests that I would eventually like to have, I place this in my <code>hello.rb</code> file:</p>
<pre>=begin
doctest: hello returns “Hello World!”
&gt;&gt; hello
=&gt; “Hello World!”
=end</pre>
<p>And to make sure that it is written correctly, we do want to run the following command and get the information back from our test:</p>
<pre>rubydoctest hello.rb
=== Testing 'hello.rb'...
ERR  | hello returns "Hello World!"
       NameError: undefined local variable or method `hello' for main:Object
         from hello.rb:3
       hello
1 comparisons, 1 doctests, 0 failures, 1 errors</pre>
<p>This information, if we pause and read it, tells us exactly what we need to get it past this error. It states &#8220;undefined local variable or method &#8216;hello&#8217;&#8221; and from which line it was called. We have already made the assumption that we want a method, and so we can do the least amount to cause this ERR to no longer exist. (You may see it as a shade of yellow in your console.)</p>
<p>So let&#8217;s write the least amount of code that we can think of to get it to not error (I placed the following on lines 6 and 7, just below the comment block):</p>
<pre>def hello
end</pre>
<p>Once I save this, and run the rubydoctest command, I get the following:</p>
<pre>rubydoctest hello.rb
=== Testing 'hello.rb'...
FAIL | hello returns "Hello World!"
       Got: nil
       Expected: "Hello World!"
         from hello.rb:4
1 comparisons, 1 doctests, 1 failures, 0 errors</pre>
<p>Depending on your settings, you should get a red &#8220;FAIL&#8221; message as well as the next three lines. Regardless you will get the summary information with 1 comparisons, 1 doctests, 1 failures and 0 errors.</p>
<p>The error count is 0, which means that we have progressed past the yellow ERR message. We will generally always want to work past ERR messages first, then FAIL messages, until we get to OK.</p>
<p>Let&#8217;s go forward in our journey and get past this FAIL message.</p>
<p>Paying attention to the feedback we get, it states that we are getting nil when we are expecting &#8220;Hello World!&#8221;. I think it is fairly obvious that we can simply have the method return the string &#8220;Hello World!&#8221; and get this to pass. Simplistic, and exactly what we want:</p>
<pre>def hello
  "Hello World!"
end</pre>
<p>Simplistic and rids us of the failure in our test:</p>
<pre>rubydoctest hello.rb
=== Testing 'hello.rb'...
 OK  | hello returns "Hello World!"
1 comparisons, 1 doctests, 0 failures, 0 errors</pre>
<p>Again, in your console, you may actually see a green OK. The important thing to note is the 0 failures and 0 errors.</p>
<h5>It continues with expanding ideas</h5>
<p>Let&#8217;s think about what we have. A <code>hello</code> method that greets the world. Not too bad. But let&#8217;s say that we want to be able to use it to greet the world, but also to greet someone in particular. Continuing our program documentation, we add the following:</p>
<pre>doctest: hello "reader" returns "Hello reader!"
&gt;&gt; hello "student"
=&gt; "Hello student!"</pre>
<p>Those three lines should be added to comment block and our entire file looks like so:</p>
<pre>=begin
doctest: hello returns "Hello World!"
&gt;&gt; hello
=&gt; "Hello World!"
doctest: hello "reader" returns "Hello reader!"
&gt;&gt; hello "student"
=&gt; "Hello student!"
=end
def hello
  "Hello World!"
end</pre>
<p>When we run the doctest (which we should do any time we make a change in either the documentation or in the code itself), we should get:</p>
<pre>rubydoctest hello.rb
=== Testing 'hello.rb'...
 OK  | hello returns "Hello World!"
ERR  | hello "reader" returns "Hello reader!"
       ArgumentError: wrong number of arguments (1 for 0)
         from hello.rb:6
       hello "student"
2 comparisons, 2 doctests, 0 failures, 1 errors</pre>
<p>From this we can see that the current way we want to use it by giving one argument is in error on line 6, because our method wants 0. That is what the &#8220;(1 for 0)&#8221; means. We are giving it one argument &#8220;student&#8221; and it is really what we want.</p>
<p>You may think that if we fix the error, the first test with either error or fail, and you would be right. When going through this process, you want to be careful to make small changes, as well as concentrating on the feature you are working on. So we will work on test hello &#8220;reader&#8221; returns &#8220;Hello reader!&#8221; until it passes. Until that happens, we will ignore the first test.</p>
<p>How might we get out of our error condition? Perhaps like this?</p>
<pre>def hello name
  "Hello World!"
end</pre>
<p>Notice how we added the argument of name to our method. We could have used something instead of name, perhaps arg or argument, but that simply states what it is, not what we should pass. In this way, what we call the argument helps to document our method as well.</p>
<p>As we have made a change, it is time to run rubydoctest again and see if we got past the error:</p>
<pre>rubydoctest hello.rb
=== Testing 'hello.rb'...
ERR  | hello returns "Hello World!"
       ArgumentError: wrong number of arguments (0 for 1)
         from hello.rb:3
       hello
FAIL | hello "reader" returns "Hello reader!"
       Got: "Hello World!"
       Expected: "Hello student!"
         from hello.rb:7
2 comparisons, 2 doctests, 1 failures, 1 errors</pre>
<p>As you can see, we went from ERR to FAIL, which is where we want to be. Ignoring the first test, we go from FAIL to OK (pass) in the simplest change we can think of:</p>
<pre>def hello name
  "Hello student!"
end</pre>
<p>Simply replacing &#8216;World&#8217; with &#8216;student&#8217;, I think, should get this test to pass:</p>
<pre>rubydoctest hello.rb
=== Testing 'hello.rb'...
ERR  | hello returns "Hello World!"
       ArgumentError: wrong number of arguments (0 for 1)
         from hello.rb:3
       hello
 OK  | hello "reader" returns "Hello reader!"
2 comparisons, 2 doctests, 0 failures, 1 errors</pre>
<p>There we go. Now we can look for any ERR messages as they are critical to allowing our program to run. It is complaining about wrong number of arguments, this time in reverse of what our second test was complaining about a few moments ago.</p>
<p>Do we want to change the test? It is something we could consider. I think I like having the ability to have default behavior of no argument to say greet the world. And so I would leave the test as it is.</p>
<p>Changing the method itself to accept 0 or more arguments is likely the right thing to do here. Let&#8217;s give that a shot:</p>
<pre>def hello *name
  “Hello student!”
end</pre>
<p>Adding the * to the argument will give us the ability to accept 0 or more arguments. Let&#8217;s test and see if we are still in an error condition:</p>
<pre>rubydoctest hello.rb
=== Testing 'hello.rb'...
FAIL | hello returns "Hello World!"
       Got: "Hello student!"
       Expected: "Hello World!"
         from hello.rb:4
 OK  | hello "reader" returns "Hello reader!"
2 comparisons, 2 doctests, 1 failures, 0 errors</pre>
<p>Seems to be OK, as we are no longer in an error condition. And a fail condition leads us where to go. We are getting “Hello student!” when we don&#8217;t give any argument. Looking above at our program, we want something a little more dynamic. Let&#8217;s use name variable to give us what we want in the string.</p>
<pre>def hello *name
  "Hello " + name + "!"
end</pre>
<p>It looks good to me, let&#8217;s see what our tests tell us?</p>
<pre>rubydoctest hello.rb
=== Testing 'hello.rb'...
ERR  | hello returns "Hello World!"
       TypeError: can't convert Array into String
         from hello.rb:3
       hello
ERR  | hello "reader" returns "Hello reader!"
       TypeError: can't convert Array into String
         from hello.rb:6
       hello "student"
2 comparisons, 2 doctests, 0 failures, 2 errors</pre>
<p>As I know that prior to this change, the additional feature passed, we will ignore any change to that, and continue to make our default behavior work.</p>
<p>What is Ruby telling us? That we can&#8217;t convert <code>Array</code> into <code>String</code> on line 3. It must be the +() method. Let&#8217;s use <code>.to_s</code> method to convert the name variable explicitly to a string:</p>
<pre>def hello *name
  "Hello " + name.to_s + "!"
end</pre>
<p>and see if that takes us away from the error:</p>
<pre>rubydoctest hello.rb
=== Testing 'hello.rb'...
FAIL | hello returns "Hello World!"
       Got: "Hello []!"
       Expected: "Hello World!"
         from hello.rb:4
FAIL | hello "reader" returns "Hello reader!"
       Got: "Hello [\"student\"]!"
       Expected: "Hello student!"
         from hello.rb:7
2 comparisons, 2 doctests, 2 failures, 0 errors</pre>
<p>Good, we are out of error mode again, and back to FAIL mode. We can deal with that, and we got some more information. We got what appears to be an empty <code>Array</code> as indicated by the [] in the string. I would guess it is because of the *name that we added. Let&#8217;s try a default value instead. Still not changing any tests&#8230; but paying attention to the feedback from the first test.</p>
<pre>def hello name='World'
  "Hello " + name.to_s + "!"
end</pre>
<p>That gets us out of fail and into OK (pass) for each test as indicated below:</p>
<pre>rubydoctest hello.rb
=== Testing 'hello.rb'...
 OK  | hello returns "Hello World!"
 OK  | hello "reader" returns "Hello reader!"
2 comparisons, 2 doctests, 0 failures, 0 errors</pre>
<h5>Refactoring in the Green</h5>
<p>You might think we are done. But we are in &#8216;green&#8217; mode and so are free to refactor our code. And looking at our code I see some things that can be improved.</p>
<pre>def hello name='World'
  "Hello + name + “!"
end</pre>
<p>Let&#8217;s use remove the <code>.to_s</code> method as we know we are going to get a string. Of course, we test after refactoring to make sure we are still good.</p>
<pre>rubydoctest hello.rb
=== Testing 'hello.rb'...
 OK  | hello returns "Hello World!"
 OK  | hello "reader" returns "Hello reader!"
2 comparisons, 2 doctests, 0 failures, 0 errors</pre>
<p>And we see we are still golden.</p>
<p>And on second thought, we can use string interpolation which to me makes it more readable, but also creates only one <code>String</code> object.</p>
<pre>def hello name='World'
  "Hello #{name}!"
end</pre>
<p>And of course, we run rubydoctest again to make sure we didn&#8217;t break anything, and we see that we are good.</p>
<p class="update"><em>I hope you found this article valuable. Feel free to ask questions and give feedback in the comments section of this post.</em> Thanks!</p>
</div>
<p>Technorati Tags: <a href="http://technorati.com/tag/Ruby+DocTest" rel="tag">Ruby DocTest</a>, <a href="http://technorati.com/tag/Programming" rel="tag">Programming</a>, <a href="http://technorati.com/tag/Ruby+programming" rel="tag">Ruby programming</a></p>
Posted by <b>Victor Goff</b><p><a href="http://www.launchbit.com/az/113-209/"><img width="468" height="60" src="http://www.launchbit.com/az-images/113-209/" /></a><br />
<small>(Powered by <a href="http://www.launchbit.com/lb/113-209/">LaunchBit</a>)</small></p>

]]></content:encoded>
			<wfw:commentRss>http://rubylearning.com/blog/2011/10/05/do-you-know-ruby-doctest/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Cloning Internet Applications with Ruby by Chang Sau Sheong</title>
		<link>http://rubylearning.com/blog/2010/10/14/cloning-internet-applications-with-ruby-by-chang-sau-sheong/</link>
		<comments>http://rubylearning.com/blog/2010/10/14/cloning-internet-applications-with-ruby-by-chang-sau-sheong/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 02:53:47 +0000</pubDate>
		<dc:creator>Victor Goff</dc:creator>
				<category><![CDATA[Book Promotions]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Chang Sau Sheong]]></category>
		<category><![CDATA[Cloning Internet Applications with Ruby]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://rubylearning.com/blog/?p=5077</guid>
		<description><![CDATA[Send to Kindle Cloning Internet Applications with Ruby by Chang Sau Sheong Cloning Internet Applications with Ruby is a new Ruby book by Chang Sau Sheong and published by Packt Publishing. It&#8217;s now for sale at $34.12 at Amazon. In India, it&#8217;s available at a special price of Rs. 837.25. This book is for those [...]<p><a href="http://www.launchbit.com/az/113-209/"><img width="468" height="60" src="http://www.launchbit.com/az-images/113-209/" /></a><br />
<small>(Powered by <a href="http://www.launchbit.com/lb/113-209/">LaunchBit</a>)</small></p>
]]></description>
				<content:encoded><![CDATA[<div class='kindleWidget kindleLight' ><img src="http://rubylearning.com/blog/wp-content/plugins/send-to-kindle/media/black-25.png" /><span>Send to Kindle</span></div><p></p>
<div class="topsy_widget_data topsy_theme_brick-red" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Frubylearning.com%252Fblog%252F2010%252F10%252F14%252Fcloning-internet-applications-with-ruby-by-chang-sau-sheong%252F%22%2C%20%22shorturl%22%3A%20%22http%3A%2F%2Fbit.ly%2F9LUiqe%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Cloning%20Internet%20Applications%20with%20Ruby%20by%20Chang%20Sau%20Sheong%22%20%7D);"></div>
<div>
<h3>Cloning Internet Applications with Ruby by Chang Sau Sheong</h3>
<p><a href="https://www.packtpub.com/cloning-internet-applications-with-ruby/book">Cloning Internet Applications with Ruby</a> is a new Ruby book by Chang Sau Sheong and published by Packt Publishing. It&#8217;s now for sale at $34.12 at Amazon. In India, it&#8217;s available at a special price of Rs. 837.25.</p>
<p class="block"><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright" src="https://www.packtpub.com/sites/default/files/imagecache/productview_ebook/1063OS_MockupCover.jpg" alt="Cloning Internet Applications with Ruby" /> <span class="drop_cap">T</span>his book is for those interested in and with some experience with web applications. The interesting thing is that the author describes four well-known applications and shows you not only how to implement each one, but describes different concerns about each type of application.</p>
<p>The author will walk you through the code, but will not teach you in-depth programming theory, instead he will show you the parts that may be used to put together clones of these four famous services. He will also go over a quick history of each service type.</p>
<p>For example, you will not even get to page sixty, and you will have a URL Shortening Clone built and deployed. He shows you the &#8216;parts&#8217; that you will use with Ruby to get it up and running. He walks you through the installation of Sinatra, Haml, and DataMapper. And then shows you how to use Blueprint CSS, Google Chart API, and HostIP. Alternatively, he goes over quickly how to deploy using Heroku.</p>
<p>The next application you will look at is TwitterClone.</p>
<p>You will use the following: JSON, GoogleClientLogin, Gravatar, and TinyURL, RPX (authentication provisioning service), TinyURL, and of course, Heroku for non-local deployment.</p>
<p>Like the first clone, you will review why he chose Twitter (kind of obvious, right?), how it is popular and valued, and some of the issues faced. He will show you a data map of the features, and by page 120, you have done it again, went from Design to Implementation, to Deployment.</p>
<p>The next exercise is cloning Flickr, and the author brings you the history, and overview, and then goes through the steps with you once again, to bring you to the last two chapters in the book, which clones Facebook! And it really isn&#8217;t as complex as you may think.</p>
<p>Have fun with this book, it will give you some insights, and may help to simplify a few tasks that you wanted to do, but were maybe intimidated by. It turns out, it isn&#8217;t as complex as it may first appear!</p>
<p><em>Have you read this book? Why don’t you share your experiences with us? Let us know in the comments section of this post. Thanks!</em></p>
</div>
<p>Technorati Tags: <a href="http://technorati.com/tag/Ruby" rel="tag">Ruby</a>, <a href="http://technorati.com/tag/Programming" rel="tag"> Programming</a>, <a href="http://technorati.com/tag/Cloning+Internet+Applications+with+Ruby" rel="tag"> Cloning Internet Applications with Ruby</a>, <a href="http://technorati.com/tag/Chang+Sau+Sheong" rel="tag"> Chang Sau Sheong</a></p>
Posted by <b>Victor Goff</b><p><a href="http://www.launchbit.com/az/113-209/"><img width="468" height="60" src="http://www.launchbit.com/az-images/113-209/" /></a><br />
<small>(Powered by <a href="http://www.launchbit.com/lb/113-209/">LaunchBit</a>)</small></p>

]]></content:encoded>
			<wfw:commentRss>http://rubylearning.com/blog/2010/10/14/cloning-internet-applications-with-ruby-by-chang-sau-sheong/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
