<?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>P is for Programming</title>
	<atom:link href="http://www.jacopretorius.net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jacopretorius.net</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 14:00:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Book Review: User Stories Applied</title>
		<link>http://www.jacopretorius.net/2012/05/book-review-user-stories-applied.html</link>
		<comments>http://www.jacopretorius.net/2012/05/book-review-user-stories-applied.html#comments</comments>
		<pubDate>Tue, 15 May 2012 14:00:38 +0000</pubDate>
		<dc:creator>Jaco Pretorius</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[UserStories]]></category>

		<guid isPermaLink="false">http://www.jacopretorius.net/?p=568</guid>
		<description><![CDATA[TLDR Version: User Stories Applied is an excellent resource for anyone who wants to gain a better understanding of the ideas behind user stories. The book has very good examples and guidelines on writing better user stories and integrating them into your development process. User Stories Applied is a book that has often been mentioned [...]]]></description>
			<content:encoded><![CDATA[<p><strong>TLDR Version</strong>:  User Stories Applied is an excellent resource for anyone who wants to gain a better understanding of the ideas behind user stories.  The book has very good examples and guidelines on writing better user stories and integrating them into your development process.</p>
<p><a href="http://www.amazon.com/User-Stories-Applied-Software-Development/dp/0321205685">User Stories Applied</a> is a book that has often been mentioned to me in the six months I&rsquo;ve been at ThoughtWorks and over the last two weeks I finally managed to get my hands on a copy.  It&rsquo;s not a very long book (230 pages) and it took me about 3 plane trips to finish it.</p>
<h4>The Good</h4>
<p>This book provides a very good outline of how user stories work and the intent behind them.  Even though I work with user stories every day I found some of the details quite refreshing &#8211; especially how user stories are not meant to contain the details behind features, but rather to be a medium for us to start discussions around features.</p>
<p>I particularly liked the discussion on how to write good user stories and the guidance on when stories are too small or too large.  This is an area where I think experience really helps, but the pointers in this book are a great starting point.</p>
<h4>The Bad</h4>
<p>Every chapter in the book ends with a summary and an outline on how the chapter influences the different roles on a development team.  I&rsquo;m not a big fan of this kind of writing &#8211; it reminds me of the textbooks I had at school and it doesn&rsquo;t seem to really add any value.</p>
<p>The second half of the book seems to focus on comparing user stories to other approaches.  I felt like the author was trying to defend user stories, but the arguments presented were more focused on the shortcomings of the other approaches rather than the advantages of user stories.  Having said that, this can be very helpful if you&rsquo;re trying to convince a client to use this practice on a project.</p>
<h4>Interesting</h4>
<p>I was rather intrigued by the difference between how the author describes user stories and what I&rsquo;m used to.  The author advocates that user stories should contain very little detail and the details should be discussed when the story is developed.  I&rsquo;m used to user stories containing most of the detail around a story &#8211; in fact stories will usually be pushed back if the details are left out.</p>
<p>I think using user stories as a placeholder for conversations around the details can work really well, but on projects with a large amount of developers (I&rsquo;m guessing more than 8 developers) the interaction with the user will quickly become a bottleneck.  User stories can therefore also work very well when they contain all the necessary details which are analysed and discussed in full before development is started &#8211; it&rsquo;s not a massive difference, but on large teams it can certainly have a massive effect.</p>
<p>User Stories Applied as an excellent resource for anyone who wants to gain a better understanding of the ideas behind user stories.  The book has very good examples and guidelines on writing better user stories and integrating them into your development process.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jacopretorius.net/2012/05/book-review-user-stories-applied.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring Postgresql on OSX Lion</title>
		<link>http://www.jacopretorius.net/2012/05/configuring-postgresql-on-osx-lion.html</link>
		<comments>http://www.jacopretorius.net/2012/05/configuring-postgresql-on-osx-lion.html#comments</comments>
		<pubDate>Thu, 03 May 2012 01:19:06 +0000</pubDate>
		<dc:creator>Jaco Pretorius</dc:creator>
				<category><![CDATA[OSX]]></category>
		<category><![CDATA[Postgresql]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.jacopretorius.net/?p=562</guid>
		<description><![CDATA[I ran into an issue today while trying to install Postgresql on OSX Lion. I followed the excellent documentation on this site &#8211; basically doing: brew install postgresql initdb /usr/local/var/postgres Then starting it with postgres -D /usr/local/var/postgres This all went great and my database was up and running! Only problem was when I tried to [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into an issue today while trying to install Postgresql on OSX Lion.  I followed the excellent documentation on <a href="http://blog.willj.net/2011/05/31/setting-up-postgresql-for-ruby-on-rails-development-on-os-x/">this site</a> &#8211; basically doing:</p>
<blockquote><p>brew install postgresql<br/><br />
initdb /usr/local/var/postgres</p>
</blockquote>
<p>Then starting it with</p>
<blockquote><p>postgres -D /usr/local/var/postgres</p>
</blockquote>
<p>This all went great and my database was up and running!  Only problem was when I tried to run a migration against my local instance &#8211; I got a page full of errors including:</p>
<blockquote><p>could not connect to server: Permission denied<br/><br />
Is the server running locally and accepting<br/><br />
connections on Unix domain socket &ldquo;/var/pgsql_socket/.s.PGSQL.5432&rdquo;?</p>
</blockquote>
<p>Luckily <a href="http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/">someone has already solved this problem</a>.  I followed the instructions on that site (which looked very promising), but I was still stuck with the same problem.</p>
<p>Lucky for me someone in the comments mentioned an additional step you might need to run if you have already run bundler:</p>
<blockquote><p>gem uninstall pg<br/><br />
gem install pg</p>
</blockquote>
<p>Hopefully this will help someone with the same problem.  Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jacopretorius.net/2012/05/configuring-postgresql-on-osx-lion.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails &#8211; The next five years</title>
		<link>http://www.jacopretorius.net/2012/04/rails-the-next-five-years.html</link>
		<comments>http://www.jacopretorius.net/2012/04/rails-the-next-five-years.html#comments</comments>
		<pubDate>Mon, 30 Apr 2012 15:00:27 +0000</pubDate>
		<dc:creator>Jaco Pretorius</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.jacopretorius.net/?p=557</guid>
		<description><![CDATA[One of the talks that I was able to attend at this year&#8217;s RailsConf was &#8216;Rails &#8211; The Next Five Years&#8217; by Yehuda Katz. I thought it was a really interesting presentation &#8211; Yehuda discussed why Rails is still relevant (after being around for 8 years) and the direction that he thinks Rails should be [...]]]></description>
			<content:encoded><![CDATA[<p>One of the talks that I was able to attend at this year&rsquo;s <a href="http://www.jacopretorius.net/2012/04/railsconf-2012.html">RailsConf</a> was &lsquo;Rails &#8211; The Next Five Years&rsquo; by <a href="http://yehudakatz.com/">Yehuda Katz</a>.  I thought it was a really interesting presentation &#8211; Yehuda discussed why Rails is still relevant (after being around for 8 years) and the direction that he thinks Rails should be going for the next few years.</p>
<p>I agreed with most of what he said and it was very thought-provoking &#8211; it really made me think about how Rails is different and what it means for everyday development as well as the future of the framework.</p>
<h4>The Ideas Underlying Rails are still controversial</h4>
<p>Rails has always promoted the idea of convention over configuration.  If you&rsquo;re using Rails every day you probably don&rsquo;t think about it, but this is actually a rather controversial idea.  Every other web-framework focuses on being flexible rather than being opinionated and trying to eliminating some of the default choices developers face on a daily basis.</p>
<p>For example, consider the REST conventions introduced in Rails 2.  Before RESTful routes were introduced we constantly had to make decisions about what we wanted our different routes and actions to look like &#8211; decisions that we had to make over and over for every application we developed.  While we did have to take some pain in switching over to RESTful routes, there were benefits which made it all worthwhile.</p>
<p>I don&rsquo;t think I&rsquo;ve ever had a conversation about how we choose our routes since then &#8211; even though the introduction of REST was a controversial decision the existance of a convention meant Rails had already made the decision for us.  In my opinion this is a good example of how the introduction of a convention has been a big win for Rails &#8211; it doesn&rsquo;t actually matter that we chose REST.  The mere introduction of the convention has removed the need for a trivial decision that we <em>all</em> had to make.</p>
<p>The other type of common problem that Rails tries to solve is problems which are very hard to understand.  A good example is XSRF protection &#8211; it&rsquo;s a reasonably tricky problem to understand, but we <em>all</em> have to deal with it.  The fact that Rails has this protection built-in means we don&rsquo;t have to worry about it &#8211; the framework solves the problem for us.</p>
<p>So Rails tries to eliminate trivial choices and solve problems which are difficult to understand by introducing conventions.  What does this mean for the future of Rails?</p>
<h4>JavaScript Applications versus HTML Applications</h4>
<p>Rails 3 has very good conventions for developing HTML applications &#8211; you get MVC, RESTful routes, helpers, a templating engine &#8211; pretty much all the different elements you need for developing an HTML application.  Where Rails doesn&rsquo;t currently have strong conventions is with developing JavaScript applications &#8211; applications which are developed using client-side frameworks such as BackBone, Spine, Ember or JavaScriptMVC.  In these types of applications Rails is primarily used for serving and consuming JSON.</p>
<p>Yehuda has been working on ActiveModel Serializers &#8211; this is a library that integrates with Rails and allows you to easily standardize the JSON being returned from your Rails.  I didn&rsquo;t actually think about it until he pointed it out, but there are various decisions to be made when returning JSON &#8211; whether or not to include id&rsquo;s, how much of the object graph to load, how associated objects should be serialized (do you include only the id or do you include the entire object), etc.  When your Rails application is primarily used for this purpose you end up having to make these decisions over and over &#8211; clearly an area where Rails could introduce some conventions to help us out.</p>
<h4>My 2 cents</h4>
<p>I agree that this is the correct direction for Rails to take &#8211; it should be easy to develop JavaScript applications with Rails.  Personally I would like to see Rails push the limits in this area and expose a Hypermedia API by default.  This means the JSON being returned would include links to the different objects being exposed by your application.  Yehuda did mention this in his presentation and I think this would be a great addition to Rails.</p>
<p>The other area I would like to see Rails standardize on is with authentication and authorization.  Currently most applications use libraries such as <a href="https://github.com/plataformatec/devise">devise</a> and it seems very strange that there is no standard solution within Rails.</p>
<p>Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jacopretorius.net/2012/04/rails-the-next-five-years.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Like Query with Mongoid</title>
		<link>http://www.jacopretorius.net/2012/04/like-query-with-mongoid.html</link>
		<comments>http://www.jacopretorius.net/2012/04/like-query-with-mongoid.html#comments</comments>
		<pubDate>Fri, 27 Apr 2012 15:00:14 +0000</pubDate>
		<dc:creator>Jaco Pretorius</dc:creator>
				<category><![CDATA[MongoDB]]></category>

		<guid isPermaLink="false">http://www.jacopretorius.net/?p=548</guid>
		<description><![CDATA[Today I had to perform a like query with Mongoid (the popular MongoDB Object-Document-Mapper). Basically I wanted something like the familiar SQL query: SELECT * FROM Users WHERE name LIKE &#8216;%bob%&#8217; I couldn&#8217;t find anything similar in the Mongoid documentation, but according to the MongoDB documentation you can do regex searches. User.where(name: /bob/) Happy coding.]]></description>
			<content:encoded><![CDATA[<p>Today I had to perform a <em>like</em> query with Mongoid (the popular MongoDB Object-Document-Mapper).  Basically I wanted something like the familiar SQL query:</p>
<blockquote><p>SELECT * FROM Users WHERE name LIKE &#8216;%bob%&#8217;</p>
</blockquote>
<p>I couldn&rsquo;t find anything similar in the Mongoid documentation, but according to the MongoDB documentation you can do regex searches.</p>
<pre class="brush: ruby;">
User.where(name: /bob/)
</pre>
<p>Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jacopretorius.net/2012/04/like-query-with-mongoid.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RailsConf 2012</title>
		<link>http://www.jacopretorius.net/2012/04/railsconf-2012.html</link>
		<comments>http://www.jacopretorius.net/2012/04/railsconf-2012.html#comments</comments>
		<pubDate>Thu, 26 Apr 2012 17:14:06 +0000</pubDate>
		<dc:creator>Jaco Pretorius</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.jacopretorius.net/?p=540</guid>
		<description><![CDATA[This week I was lucky enough to be able to attend RailsConf in Austin, Texas. As far as I know this is the biggest Rails conference in the world and it was really exciting to see all the big names in the Rails community. The conference took place over 3 days with various keynotes and [...]]]></description>
			<content:encoded><![CDATA[<p>This week I was lucky enough to be able to attend RailsConf in Austin, Texas.  As far as I know this is the biggest Rails conference in the world and it was really exciting to see all the big names in the Rails community.</p>
<p>The conference took place over 3 days with various keynotes and 3 different tracks as well as numerous smaller sessions.  As you would expect from a conference of this status all the speakers set a very high standard and all the keynotes were very thought-provoking.  I really enjoyed all the session I attended &#8211; from the opening keynote by <a href="http://david.heinemeierhansson.com/">DHH</a> to the lightning talks on the last day.</p>
<p>Some of my highlights were the opening keynote, as well as the sessions by <a href="http://www.steveklabnik.com/">Steve Klabnik</a> and <a href="http://yehudakatz.com/">Yehuda Katz</a>.  Steve is very well-known for his work on Hypermedia APIs (which was also the topic of his session).  Yehuda Katz presented a very thought-provoking session on the future of Rails.</p>
<p>I would definitely recommend the conference to any Rails developer &#8211; it&rsquo;s a great way to open your eyes to the different technologies around Rails as well as get to meet other developers.</p>
<p>Overall I think the conference was a massive success and I would recommend it to any developer.  Austin was the (awesome) venue which meant I also got to sample some of the local food and enjoy some of the local attractions &#8211; what could be better?</p>
<p><img src="https://lh6.googleusercontent.com/-H78NTv10c5k/T5ivIZpM0lI/AAAAAAAAAmw/YTBGLo4U7GQ/s400/Photo%2520Apr%252023%252C%25208%252052%252020%2520AM.jpg" alt="railsconf" class="shadow" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jacopretorius.net/2012/04/railsconf-2012.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[BUG] cross-thread violation on rb_gc()</title>
		<link>http://www.jacopretorius.net/2012/04/bug-cross-thread-violation-on-rb_gc.html</link>
		<comments>http://www.jacopretorius.net/2012/04/bug-cross-thread-violation-on-rb_gc.html#comments</comments>
		<pubDate>Tue, 24 Apr 2012 15:43:00 +0000</pubDate>
		<dc:creator>Jaco Pretorius</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.jacopretorius.net/?p=537</guid>
		<description><![CDATA[I was recently involved in upgrading a project from Ruby 1.9.2 to 1.9.3. As part of this upgrade we also upgraded several of our gems (including Rails) to the latest versions. Everything went smoothly, but when I tried to run the latest version of the code on my laptop (MacBook Pro) I got the following [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently involved in upgrading a project from Ruby 1.9.2 to 1.9.3.  As part of this upgrade we also upgraded several of our gems (including Rails) to the latest versions.  Everything went smoothly, but when I tried to run the latest version of the code on my laptop (MacBook Pro) I got the following error:</p>
<blockquote><p>[BUG] cross-thread violation on rb_gc()</p>
</blockquote>
<p>I was using RVM and bundler, so as far as I knew (which isn&rsquo;t all that far) everything <em>should</em> just work.</p>
<p>I did what every responsible dev would do &#8211; I googled the error message.  Unfortunately this doesn&rsquo;t seem to be a very common problem and most of the solutions involved removing and reinstalling the json gem (which didn&rsquo;t work for me).</p>
<p>I tried quite a few solutions, including nuking all local gems (so gems not installed through bundler) &#8211; no luck.  I also reinstalled Ruby 1.9.3 &#8211; no luck.  I even pulled down the project into a different directory and I still got the same error.</p>
<p>In the end the problem was with the RVM gemset.  I simply removed and recreated the RVM gemset and this fixed the problem.</p>
<blockquote><p>rvm gemset delete your_gemset_name</p>
</blockquote>
<p>Hopefully this will help someone else with the same problem.  Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jacopretorius.net/2012/04/bug-cross-thread-violation-on-rb_gc.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Comment Ruby code with Vim</title>
		<link>http://www.jacopretorius.net/2012/03/comment-ruby-code-with-vim.html</link>
		<comments>http://www.jacopretorius.net/2012/03/comment-ruby-code-with-vim.html#comments</comments>
		<pubDate>Thu, 01 Mar 2012 15:00:32 +0000</pubDate>
		<dc:creator>Jaco Pretorius</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.jacopretorius.net/?p=532</guid>
		<description><![CDATA[I&#8217;ve recently started using Vim for Ruby/Rails development. As someone who is very new to Vim it has been a steep learning curve, but I&#8217;m really enjoying it &#8211; it has definitely become my editor of choice. One of the useful little tricks I figured out today is how to comment out a block of [...]]]></description>
			<content:encoded><![CDATA[<p>I&rsquo;ve recently started using Vim for Ruby/Rails development.  As someone who is very new to Vim it has been a steep learning curve, but I&rsquo;m really enjoying it &#8211; it has definitely become my editor of choice.  One of the useful little tricks I figured out today is how to comment out a block of Ruby code.</p>
<p>Here&rsquo;s what to do.</p>
<ol>
<li>Navigate to the beginning of the first line you want to comment</li>
<li>Press Ctrl + v</li>
<li>Select the lines you want to comment with j and k</li>
<li>Press Shift + i</li>
<li>Press #</li>
<li>Press Esc</li>
</ol>
<p>Voila!  If you want to do the opposite follow steps 1 to 3 and then simply press d.</p>
<p>This is really just multi-line editing.  Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jacopretorius.net/2012/03/comment-ruby-code-with-vim.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Closures in Ruby</title>
		<link>http://www.jacopretorius.net/2012/02/closures-in-ruby.html</link>
		<comments>http://www.jacopretorius.net/2012/02/closures-in-ruby.html#comments</comments>
		<pubDate>Wed, 15 Feb 2012 15:00:30 +0000</pubDate>
		<dc:creator>Jaco Pretorius</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.jacopretorius.net/?p=526</guid>
		<description><![CDATA[The complete title for this post is: Closures in Ruby make my head hurt. I&#8217;ve had a rough idea of how closures work (from my JavaScript experience), but I just watched An Introduction Blocks, Lambdas and Closures in Ruby and I&#8217;ve realized that I my knowledge is a mere drop in the ocean. I would [...]]]></description>
			<content:encoded><![CDATA[<p>The complete title for this post is: Closures in Ruby make my head hurt.  I&rsquo;ve had a rough idea of how closures work (from my JavaScript experience), but I just watched <a href="http://www.youtube.com/watch?v=VBC-G6hahWA">An Introduction Blocks, Lambdas and Closures in Ruby</a> and I&rsquo;ve realized that I my knowledge is a mere drop in the ocean.</p>
<p>I would highly recommend this video to anyone who is looking for a better understanding of these three topics.</p>
<p>To get started, let&rsquo;s look at a very basic example of a closure.</p>
<pre class="brush: ruby;">
def run_proc(p)
  p.call
end

name = "Bob"
puts_name = proc { puts name }
run_proc puts_name
# Bob
</pre>
<p>This code obviously works, but keep in mind what is really going on here &ndash; we are creating a proc which references the <em>name</em> variable.  We then execute the block in the context of the run_proc method, where the <em>name</em> variable doesn&rsquo;t exist!  So this little snippet of code is actually doing something really complex.</p>
<p>Ruby actually attaches the <em>name</em> variable to the block which then makes it available when we want to use it!  This is called a <strong>closure</strong>.</p>
<p>Let&rsquo;s look at another example, using a lambda instead of a proc.</p>
<pre class="brush: ruby;">
def run_lambda(l, val)
  l[val]
end

a = 5
multiply_by_a = lambda do |x|
  x * a
end

puts run_lambda(multiply_by_a, 2)
# 10
</pre>
<p>Again, this works as we expected it to &ndash; the <em>a</em> variable is attached to the lambda and can be accessed when the lambda is executed.  Now we can try something really strange.</p>
<pre class="brush: ruby;">
def run_lambda(l, val)
  l[val]
end

a = 5
multiply_by_a = lambda do |x|
  x * a
end

a = 10
puts run_lambda(multiply_by_a, 3)
# 30
</pre>
<p>What this snippet is illustrating is that Ruby closures actually attach a reference to the variable being used.  That&rsquo;s why we can update the a variable and have the lambda use the updated value &ndash; this is actually different to how a number of other languages implement closures.  Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jacopretorius.net/2012/02/closures-in-ruby.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alias class methods in Ruby</title>
		<link>http://www.jacopretorius.net/2012/02/alias-class-methods-in-ruby.html</link>
		<comments>http://www.jacopretorius.net/2012/02/alias-class-methods-in-ruby.html#comments</comments>
		<pubDate>Tue, 14 Feb 2012 15:10:41 +0000</pubDate>
		<dc:creator>Jaco Pretorius</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.jacopretorius.net/?p=517</guid>
		<description><![CDATA[Yesterday I came across a problem where one possible solution was to alias a class method. I&#8217;ve blogged about aliasing methods before, but I didn&#8217;t know how to do this for class methods. Turns out, it&#8217;s pretty simple &#8211; the syntax is just a bit different. class Person def self.all %w{ Bob Steve } end [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I came across a problem where one possible solution was to alias a class method.  I&rsquo;ve blogged about <a href="http://www.jacopretorius.net/2012/01/alias-methods-in-ruby.html">aliasing methods</a> before, but I didn&rsquo;t know how to do this for class methods.</p>
<p>Turns out, it&rsquo;s pretty simple &ndash; the syntax is just a bit different.</p>
<pre class="brush: ruby;">
class Person
  def self.all
    %w{ Bob Steve }
  end

  class << self
    alias_method &#58;old_all, :all

    def all
      old = self.old_all
      old << "Peter"
      old << "Owen"
    end
  end
end

p Person.old_all
# ["Bob", "Steve"]
p Person.all
# ["Bob", "Steve", "Peter", "Owen"]
</pre>
<p>Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jacopretorius.net/2012/02/alias-class-methods-in-ruby.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Zip in Ruby</title>
		<link>http://www.jacopretorius.net/2012/02/using-zip-in-ruby.html</link>
		<comments>http://www.jacopretorius.net/2012/02/using-zip-in-ruby.html#comments</comments>
		<pubDate>Mon, 13 Feb 2012 15:00:26 +0000</pubDate>
		<dc:creator>Jaco Pretorius</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.jacopretorius.net/?p=513</guid>
		<description><![CDATA[Last week I blogged about the Enumerable module in Ruby and specifically mentioned the Enumerable#zip method. I didn&#8217;t think the zip method was particularly useful, but I have actually found a few extra features which are very nice. To refresh your memory, the zip method will combine the elements of two different arrays. names = [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I blogged about the <a href="http://www.jacopretorius.net/2012/02/exploring-enumerable-in-ruby.html">Enumerable module in Ruby</a> and specifically mentioned the <strong>Enumerable#zip</strong> method.  I didn&rsquo;t think the <strong>zip</strong> method was particularly useful, but I have actually found a few extra features which are very nice.</p>
<p>To refresh your memory, the <strong>zip</strong> method will combine the elements of two different arrays.</p>
<pre class="brush: ruby;">
names = %w{ Michael Tobias Ann Barry }
surnames = %w{ Bluth Funke Veal Zuckerkorn }

p names.zip(surnames)
# [["Michael", "Bluth"], ["Tobias", "Funke"], ["Ann", "Veal"], ["Barry","Zuckerkorn"]]
</pre>
<p>I also mentioned that you can actually combine multiple arrays in this way.</p>
<pre class="brush: ruby;">
names = %w{ Michael Tobias Ann Barry }
surnames = %w{ Bluth Funke Veal Zuckerkorn }
ages = [ 42, 44, 17, 49 ]

p names.zip(surnames, ages)
# [["Michael", "Bluth", 42], ["Tobias", "Funke", 44], ["Ann", "Veal", 17], ["Barry","Zuckerkorn", 49]]
</pre>
<p>What I didn&rsquo;t realize was that you can very easily create a hash mapping between two arrays when you use this method in combination with the [] method on the Hash class.</p>
<pre class="brush: ruby;">
names = %w{ Michael Tobias Ann Barry }
surnames = %w{ Bluth Funke Veal Zuckerkorn }

p Hash[names.zip(surnames)]
# {"Tobias"=>"Funke", "Michael"=>"Bluth", "Ann"=>"Veal", "Barry"=>"Zuckerkorn"}
</pre>
<p>This is a pretty cool trick.  Lastly, we can actually pass a <strong>block</strong> to the <strong>zip</strong> method &ndash; the block will execute exactly the same as an <strong>each</strong> block executed on the result.</p>
<pre class="brush: ruby;">
names = %w{ Michael Tobias Ann Barry }
surnames = %w{ Bluth Funke Veal Zuckerkorn }
ages = [ 42, 44, 17, 49 ]

names.zip(surnames, ages) do |elem|
  p elem
end
# ["Michael", "Bluth", 42]
# ["Tobias", "Funke", 44]
# ["Ann", "Veal", 17]
# ["Barry", "Zuckerkorn", 49]
</pre>
<p>I still don&rsquo;t really get the name of the method, but it&rsquo;s pretty useful.  Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jacopretorius.net/2012/02/using-zip-in-ruby.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

