<?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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Know Ruby</title>
	<atom:link href="http://knowruby.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://knowruby.wordpress.com</link>
	<description>A daily dose of Ruby</description>
	<lastBuildDate>Mon, 20 Jun 2011 22:34:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='knowruby.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Know Ruby</title>
		<link>http://knowruby.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://knowruby.wordpress.com/osd.xml" title="Know Ruby" />
	<atom:link rel='hub' href='http://knowruby.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Working with Ruby Blocks</title>
		<link>http://knowruby.wordpress.com/2009/04/08/working-ruby-blocks/</link>
		<comments>http://knowruby.wordpress.com/2009/04/08/working-ruby-blocks/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 19:23:22 +0000</pubDate>
		<dc:creator>iLya Lozovyy</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://knowruby.wordpress.com/?p=82</guid>
		<description><![CDATA[Working with Ruby Blocks or pieces of code that you might want to pass around in your business logic without having to replicate the same code everywhere.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=knowruby.wordpress.com&amp;blog=7053895&amp;post=82&amp;subd=knowruby&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s topic deals with blocks in ruby. So the first question that you might ask is what is a block.<br />
I will fall back to my C# experience in order to try and explain what a block is.<br />
A block is a piece of code that you want to execute within a context of another piece of code.<br />
I will use a string Array as an example in C# to show you what I mean. The code below creates a new instance of an array that is populated with 3 different names. I then use what is called an <a href="http://msdn.microsoft.com/en-us/library/018hxwa8.aspx">Action</a> to loop through each string in the array and write the name to the console.<br />
Here is what the code looks like.</p>
<p>
public void DisplayNames()
{
	string[] names =
		new string[] {&quot;Bob&quot;, &quot;John&quot;, &quot;Sam&quot;};
	Array.ForEach(names,
		name =&gt; Console.WriteLine(name));
}
</p>
<p>and here is what the Ruby code looks like:</p>
<p><pre class="brush: ruby;">
def DisplayNames
  names = %w( Bob John Sam )
  names.each do |name|
    puts name
  end
end
</pre></p>
<p>The basic idea behind using blocks is that you want to perform some sort of a generic action that can be used throughout your application but you don&#8217;t want to duplicate the same code all over. In this case you can use blocks to perform this action of looping through your array and just specifying what should happen to each item.</p>
<p>The basic implementation of the ruby <strong>each</strong> function looks like this:</p>
<p><pre class="brush: ruby;">
def print_values(list)
    for item in list
        yield(item)
    end
end
</pre></p>
<p>One interesting thing that I would like to point out is that there are different ways to pass a block to the method.<br />
<pre class="brush: ruby;">
names = %w( Bob John Sam )
print_values(names) { |name| puts name }
</pre></p>
<p><strong>or</strong></p>
<p><pre class="brush: ruby;">
names = %w( Bob John Sam )
print_values(names) do |name|
    puts name
end
</pre></p>
<p>What you see here is that we are creating an array of values and then we are passing that array to the <em>print_values</em> method which will perform the iteration logic over the array and will call the block after the <em>print_values(names)</em> call in order to perform what ever the logic in that block is. The <em>yield</em> keyword is what enables the call to the given block of code and it passes the variable that we are currently iterating over.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/knowruby.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/knowruby.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/knowruby.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/knowruby.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/knowruby.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/knowruby.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/knowruby.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/knowruby.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/knowruby.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/knowruby.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/knowruby.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/knowruby.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/knowruby.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/knowruby.wordpress.com/82/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=knowruby.wordpress.com&amp;blog=7053895&amp;post=82&amp;subd=knowruby&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://knowruby.wordpress.com/2009/04/08/working-ruby-blocks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/012260cd97b101a2d8e8341627f3f9ba?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">ilyalozovyy</media:title>
		</media:content>
	</item>
		<item>
		<title>Passing multiple arguments to functions in Ruby</title>
		<link>http://knowruby.wordpress.com/2009/04/07/passing-multiple-arguments-functions-ruby/</link>
		<comments>http://knowruby.wordpress.com/2009/04/07/passing-multiple-arguments-functions-ruby/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 12:38:17 +0000</pubDate>
		<dc:creator>iLya Lozovyy</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://knowruby.wordpress.com/?p=69</guid>
		<description><![CDATA[Passing multiple arguments to functions<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=knowruby.wordpress.com&amp;blog=7053895&amp;post=69&amp;subd=knowruby&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I wanted to talk about passing multiple arguments to functions. This can be a very useful piece of functionality if used correctly. One good example of passing multiple values to a function would be is when an application needs to validate multiple email addresses before an email is sent out to all the people in the list. This way the method signature looks very clean and all the consumer of the method has to do is simply pass in an array of all of the emails that they want to validate.</p>
<p>Let’s take the following code as an example of what it would look like.</p>
<p>
<pre class="brush: ruby;">
def return_valid_emails(*email_list)
    new_list = Array.new
    email_list.each do |email|
        new_list &lt;&lt; email unless not email.valid?
    end
    new_list
end
return_valid_emails(&quot;valid@email.com&quot;,&quot;invalid.com&quot;)
</pre><br />
</p>
<p>The method above has a strange looking variable that has a “*” symbol saying that the argument is a variable array of items. Once we are inside of that method the “email_list” variable is treated as a normal Array and we can write some logic to iterate through items in the Array and perform our validation logic.</p>
<p>This logic consists of creating a new Array of emails and we populate that new Array by iterating through the given list of emails and validating each one. After the iteration is complete we simply return the new Array to the caller. The output of the call should be the following:</p>
<blockquote><p>[“valid@email.com”]</p>
</blockquote>
<p>If anyone has any other questions in regards to what is happening in this method don’t hesitate to ask.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/knowruby.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/knowruby.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/knowruby.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/knowruby.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/knowruby.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/knowruby.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/knowruby.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/knowruby.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/knowruby.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/knowruby.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/knowruby.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/knowruby.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/knowruby.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/knowruby.wordpress.com/69/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=knowruby.wordpress.com&amp;blog=7053895&amp;post=69&amp;subd=knowruby&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://knowruby.wordpress.com/2009/04/07/passing-multiple-arguments-functions-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/012260cd97b101a2d8e8341627f3f9ba?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">ilyalozovyy</media:title>
		</media:content>
	</item>
		<item>
		<title>How to cache values in a variables</title>
		<link>http://knowruby.wordpress.com/2009/04/06/cache-values-variables/</link>
		<comments>http://knowruby.wordpress.com/2009/04/06/cache-values-variables/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 12:04:36 +0000</pubDate>
		<dc:creator>iLya Lozovyy</dc:creator>
				<category><![CDATA[Caching]]></category>

		<guid isPermaLink="false">http://knowruby.wordpress.com/?p=54</guid>
		<description><![CDATA[How to cache values in ruby.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=knowruby.wordpress.com&amp;blog=7053895&amp;post=54&amp;subd=knowruby&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Coming from a .NET background I was always used to using properties in my classes in order to either expose the values of my variables to the consumer of my class or to perform some sort of caching so I don’t have to have the same logic duplicated throughout my class.<br />
An example of that code might look like this:<br />
public class TestClass
{
  string _firstName;
  public string FirstName
  {
   get
    {
     if(string.IsNullOrEmpty(_firstName))
     {
      _firstName = UserDAL.GetFirstName();
     }
     return _firstName;
    }
  }
}
<br />
After starting to learn Ruby On Rails I have learned that there is a very simple way to do the same thing with much less code.<br />
<pre class="brush: ruby;">def class TestClass
 def first_name
  @firstname ||= User.first.FirstName
 end
end
</pre><br />
One thing to watch out for is that the ruby code above checks to see if the value of the variable is not null and it will return the value that is set. This means that if you wanted to return a result based on a constantly changing criteria then this is not the correct way of performing caching because the statement that occurs after the “||=” only gets evaluated once unless the result of that statement returns nil.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/knowruby.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/knowruby.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/knowruby.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/knowruby.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/knowruby.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/knowruby.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/knowruby.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/knowruby.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/knowruby.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/knowruby.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/knowruby.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/knowruby.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/knowruby.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/knowruby.wordpress.com/54/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=knowruby.wordpress.com&amp;blog=7053895&amp;post=54&amp;subd=knowruby&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://knowruby.wordpress.com/2009/04/06/cache-values-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/012260cd97b101a2d8e8341627f3f9ba?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">ilyalozovyy</media:title>
		</media:content>
	</item>
		<item>
		<title>Making your code look pretty in WordPress posts</title>
		<link>http://knowruby.wordpress.com/2009/04/05/font-colorb4c24bmaking-code-pretty-wordpress-postsfont/</link>
		<comments>http://knowruby.wordpress.com/2009/04/05/font-colorb4c24bmaking-code-pretty-wordpress-postsfont/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 02:23:30 +0000</pubDate>
		<dc:creator>iLya Lozovyy</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://knowruby.wordpress.com/?p=23</guid>
		<description><![CDATA[Using Wordpress built-in code formatting to make your source code look better.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=knowruby.wordpress.com&amp;blog=7053895&amp;post=23&amp;subd=knowruby&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Since the very first time when I started this blog I have been trying to find a better way of formatting my code. I am using Windows Live Writer to write and post my blogs and it has a lot of good plug-ins to not only format your code but many other things such as inserting pictures, videos, maps, and many many more. However I was not able to find a good plug-in to format my code and I started digging around. I am partially writing this post so I can later use this post as a reference for my self and others if they are interested.</p>
<p>What I have found out is that WordPress is already supporting a great code formatter tool that was written by Alex Gorbatchev called <a href="http://code.google.com/p/syntaxhighlighter/" target="_blank">Syntaxhighlighter</a>.<br />
All you have to do in order to format your code is to enclose it into a sourcecode block and the wordpress engine will take care of formatting your code based on the language that you specified. Here is a simple example of what a piece of ruby code might look like:</p>
<p>[ sourcecode language='ruby']<br />
def class BeautifulCode<br />
  def display_beautiful_code<br />
    puts &#8220;SyntaxHighlither rocks!!&#8221;<br />
  end<br />
end<br />
[ /sourcecode]</p>
<p>The output after formatting will look like this.</p>
<p><pre class="brush: ruby;">
def class BeautifulCode
  def display_beautiful_code
    puts &quot;SyntaxHighlither rocks!!&quot;
  end
end
</pre></p>
<p>Just make sure to remove the spaces that I have intentionally included in the first source code sample because WordPress would otherwise try to display the formatter version instead of the actual code that I was trying to display.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/knowruby.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/knowruby.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/knowruby.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/knowruby.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/knowruby.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/knowruby.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/knowruby.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/knowruby.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/knowruby.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/knowruby.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/knowruby.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/knowruby.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/knowruby.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/knowruby.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=knowruby.wordpress.com&amp;blog=7053895&amp;post=23&amp;subd=knowruby&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://knowruby.wordpress.com/2009/04/05/font-colorb4c24bmaking-code-pretty-wordpress-postsfont/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/012260cd97b101a2d8e8341627f3f9ba?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">ilyalozovyy</media:title>
		</media:content>
	</item>
		<item>
		<title>Formatting ActiveRecord messages in Rails 2.x</title>
		<link>http://knowruby.wordpress.com/2009/03/29/formatting-activerecord-messages-in-rails-2x/</link>
		<comments>http://knowruby.wordpress.com/2009/03/29/formatting-activerecord-messages-in-rails-2x/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 23:51:48 +0000</pubDate>
		<dc:creator>iLya Lozovyy</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Localization]]></category>

		<guid isPermaLink="false">http://knowruby.wordpress.com/2009/03/29/formatting-activerecord-messages-in-rails-2x/</guid>
		<description><![CDATA[Last week I was reading a chapter in a RailsSpaces book and because the book was written in 2007 the code was a bit outdated. The issue that I was running into was the author was using the sprintf() function to format a string that is part of the ActiveRecord error messages. This is a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=knowruby.wordpress.com&amp;blog=7053895&amp;post=6&amp;subd=knowruby&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Last week I was reading a chapter in a <a href="http://www.amazon.com/RailsSpace-Building-Networking-Addison-Wesley-Professional/dp/0321480791/ref=sr_1_1/183-9626655-7633802?ie=UTF8&amp;s=books&amp;qid=1238368901&amp;sr=1-1">RailsSpaces</a> book and because the book was written in 2007 the code was a bit outdated. The issue that I was running into was the author was using the sprintf() function to format a string that is part of the ActiveRecord error messages. This is a problem because the ActiveRecord uses error messages such as :</p>
<blockquote><p>&#8220;is too short (minimum is {{count}} characters)”</p></blockquote>
<p>where the word in the double curly braces is the placeholder for the value that the developer must replace. I first thought that I simply was not using the sprintf() function correctly until I discovered that the sprintf() was the wrong method to use in the first place. What should be used is a new class that was introduced to Rails in version 2 called I18n which is a new way of localizing the text in rails applications. The correct way of formatting those kinds of messages in Rails now is:</p>
<p><pre class="brush: ruby;">I18n.translate(&quot;activerecord.errors.messages.too_short&quot;,
				:count=&gt; some_value)</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/knowruby.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/knowruby.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/knowruby.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/knowruby.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/knowruby.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/knowruby.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/knowruby.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/knowruby.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/knowruby.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/knowruby.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/knowruby.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/knowruby.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/knowruby.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/knowruby.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=knowruby.wordpress.com&amp;blog=7053895&amp;post=6&amp;subd=knowruby&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://knowruby.wordpress.com/2009/03/29/formatting-activerecord-messages-in-rails-2x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/012260cd97b101a2d8e8341627f3f9ba?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">ilyalozovyy</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting introduced to BDD using RSpec</title>
		<link>http://knowruby.wordpress.com/2009/03/24/getting-introduced-to-bdd-using-rspec/</link>
		<comments>http://knowruby.wordpress.com/2009/03/24/getting-introduced-to-bdd-using-rspec/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 05:03:11 +0000</pubDate>
		<dc:creator>iLya Lozovyy</dc:creator>
				<category><![CDATA[RSpec]]></category>
		<category><![CDATA[BDD]]></category>

		<guid isPermaLink="false">http://knowruby.wordpress.com/2009/03/24/getting-introduced-to-bdd-using-rspec/</guid>
		<description><![CDATA[Today I had a great opportunity to attend one of the local Ruby User Groups in Cleveland OH. It was a very interesting experience where a group of people were trying to solve a problem. The problem that they were trying to solve is to implement a bowling calculation class using BDD and RSpec. The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=knowruby.wordpress.com&amp;blog=7053895&amp;post=5&amp;subd=knowruby&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I had a great opportunity to attend one of the local Ruby User Groups in Cleveland OH. It was a very interesting experience where a group of people were trying to solve a problem. The problem that they were trying to solve is to implement a bowling calculation class using BDD and RSpec. The group consisted of 6 people but only 2 people were working on a problem at any point and time where one person would sit down and write the test and hand the keyboard and mouse to the other person and have them write the minimal amount of code to make the test pass. After 10 minutes of going back and forward the person who was writing the code to pass the tests walked away from the computer and the person writing the tests ended up in the driver seat to write the code and a new person would come in to write the tests. <br />I was amazed at how easy it was to write the test and then have to write the code to satisfy the test. <br />I have made my first attempt at writing my very first test and below you can see the results of a very interesting factory class and a RSpec test that I ended up writing.</p>
<p>In order to run the code that I have below you will have to make sure that you have RubyGems and RSpec gem installed. </p>
<div id="codeSnippetWrapper" style="border-right:silver 1px solid;border-top:silver 1px solid;font-size:8pt;overflow:auto;border-left:silver 1px solid;width:98.91%;cursor:text;direction:ltr;line-height:12pt;border-bottom:silver 1px solid;font-family:'Courier New', courier, monospace;height:250px;background-color:#f4f4f4;text-align:left;max-height:200px;margin:20px 0 10px;padding:4px;">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> # factory_spec.rb</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> require <span style="color:#006080;">'rubygems'</span></pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span> gem <span style="color:#006080;">'rspec'</span></pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span> require <span style="color:#006080;">'factory'</span></pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>&nbsp; </pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span> describe <span style="color:#006080;">"should test factory's output"</span> <span style="color:#0000ff;">do</span></pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>     before(:each) <span style="color:#0000ff;">do</span></pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>         @factory = Factory.<span style="color:#0000ff;">new</span></pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>         @factory.make_cars(0)</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>     end</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>     </pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>     it <span style="color:#006080;">"should return 0 when 0 is passed as an argument"</span> <span style="color:#0000ff;">do</span></pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>         @factory.daily_output.should == 0</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>     end</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span> end</pre>
<p><!--CRLF--></div>
</div>
<p>Here is the sample class that I wrote in order to satisfy the test that is written above:</p>
<div id="codeSnippetWrapper" style="border-right:silver 1px solid;border-top:silver 1px solid;font-size:8pt;overflow:auto;border-left:silver 1px solid;width:99.32%;cursor:text;direction:ltr;line-height:12pt;border-bottom:silver 1px solid;font-family:'Courier New', courier, monospace;height:154px;background-color:#f4f4f4;text-align:left;max-height:200px;margin:20px 0 10px;padding:4px;">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> #factory.rb</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> <span style="color:#0000ff;">class</span> Factory</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     def make_cars(carcount)</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>         @blah = carcount</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>     end</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>     def daily_output</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>         @blah</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>     end</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span> end</pre>
<p><!--CRLF--></div>
</div>
<p>Then to run the code below you will have to execute the following command: </p>
<div id="codeSnippetWrapper" style="border-right:silver 1px solid;border-top:silver 1px solid;font-size:8pt;overflow:auto;border-left:silver 1px solid;width:97.5%;cursor:text;direction:ltr;line-height:12pt;border-bottom:silver 1px solid;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;max-height:200px;margin:20px 0 10px;padding:4px;">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> spec -f s --c factory_spec.rb</pre>
<p><!--CRLF--></div>
</div>
<p>And the output of the above test looks like this:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> ilya@RubyDev:~/projects/ruby/testing$ spec -f s --c factory_spec.rb</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>&nbsp; </pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span> should test factory's output</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span> - should <span style="color:#0000ff;">return</span> 0 when 0 is passed as an argument</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>&nbsp; </pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span> Finished <span style="color:#0000ff;">in</span> 0.003434 seconds</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>&nbsp; </pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span> 1 example, 0 failures</pre>
<p><!--CRLF-->
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<p><!--CRLF--></div>
</div>
<p>After having to get my hands dirty writing this test things all of a sudden started making sense. Having to write tests before writing the code seems like a lot of work for a beginner TDD or BDD coder but after some time the benefits of having to think about the requirement and then coding makes you think about the problem at hand and then appropriately coding a solution.</p>
<p>If you have any comments please do not hesitate to respond and I can try my best to answer any questions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/knowruby.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/knowruby.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/knowruby.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/knowruby.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/knowruby.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/knowruby.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/knowruby.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/knowruby.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/knowruby.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/knowruby.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/knowruby.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/knowruby.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/knowruby.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/knowruby.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=knowruby.wordpress.com&amp;blog=7053895&amp;post=5&amp;subd=knowruby&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://knowruby.wordpress.com/2009/03/24/getting-introduced-to-bdd-using-rspec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/012260cd97b101a2d8e8341627f3f9ba?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">ilyalozovyy</media:title>
		</media:content>
	</item>
		<item>
		<title>The start of a wonderful journey</title>
		<link>http://knowruby.wordpress.com/2009/03/22/the-start-of-a-wonderful-journey/</link>
		<comments>http://knowruby.wordpress.com/2009/03/22/the-start-of-a-wonderful-journey/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 03:58:00 +0000</pubDate>
		<dc:creator>iLya Lozovyy</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://knowruby.wordpress.com/2009/03/22/the-start-of-a-wonderful-journey/</guid>
		<description><![CDATA[Today I am starting two new things. 1) Starting my own blog. 2) Learning ruby. I am taking this journey for a couple of different reasons. One is that I always wanted to blog about something which I am passionate about and the second is because I started learning ruby and I am not finding [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=knowruby.wordpress.com&amp;blog=7053895&amp;post=4&amp;subd=knowruby&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I am starting two new things.    </p>
<p>1) Starting my own blog.     <br />2) Learning ruby.</p>
<p>I am taking this journey for a couple of different reasons. One is that I always wanted to blog about something which I am passionate about and the second is because I started learning ruby and I am not finding as much information about it as I thought I should. I hope that by starting this blog I can document my experiences of learning ruby and hopefully share it with the rest of the ruby community.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/knowruby.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/knowruby.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/knowruby.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/knowruby.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/knowruby.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/knowruby.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/knowruby.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/knowruby.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/knowruby.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/knowruby.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/knowruby.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/knowruby.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/knowruby.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/knowruby.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=knowruby.wordpress.com&amp;blog=7053895&amp;post=4&amp;subd=knowruby&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://knowruby.wordpress.com/2009/03/22/the-start-of-a-wonderful-journey/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/012260cd97b101a2d8e8341627f3f9ba?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">ilyalozovyy</media:title>
		</media:content>
	</item>
	</channel>
</rss>
