<?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>Thinking In Rails &#187; Instructions</title>
	<atom:link href="http://thinkinginrails.com/category/instructions/feed/" rel="self" type="application/rss+xml" />
	<link>http://thinkinginrails.com</link>
	<description>A Perl Programmer&#039;s Exploration of The World of Ruby on Rails</description>
	<lastBuildDate>Thu, 12 Apr 2012 03:37:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Ruby and Rails on Windows Finally Simple?</title>
		<link>http://thinkinginrails.com/2011/01/ruby-and-rails-on-windows-finally-simple/</link>
		<comments>http://thinkinginrails.com/2011/01/ruby-and-rails-on-windows-finally-simple/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 17:36:06 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[Instructions]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Installer]]></category>
		<category><![CDATA[RVM]]></category>
		<category><![CDATA[Wayne]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://thinkinginrails.com/?p=642</guid>
		<description><![CDATA[Remember a bit ago when Wayne E. Seguin of RVM Fame (I think he should legally change his name to that BTW) was hired by Engine Yard to do, among other things, help get Rails working properly on Windows? Well, looks like in only weeks of work, there is now Ruby and Rails on Windows [...]]]></description>
			<content:encoded><![CDATA[<p>Remember a bit ago when Wayne E. Seguin of RVM Fame (I think he should legally change his name to that BTW) was hired by Engine Yard to do, among other things, help get Rails working properly on Windows?  Well, looks like in only weeks of work, there is now <a href="http://www.rubyinside.com/rails-installer-ruby-and-rails-on-windows-in-a-single-install-4201.html">Ruby and Rails on Windows in a Single, Easy Install</a>.</p>
<p>If this works as advertised (haven&#8217;t had a chance to test it yet), then this is huge in giving Ruby on Rails a big edge into the Windows world, and eliminates the need for such hacky (sorry Curtis) solutions like <a href="http://www.curtismchale.ca/tutorials/the-best-windows-ruby-on-rails-setup-part-1-screentcast/">this</a>, previously the &#8220;best&#8221; way to run Rails on Windows <img src='http://thinkinginrails.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Not only that, but this gives Rails on Windows almost the same advantage it has for development on Mac and Linux: stupidly low barrier to entry.  Rails has always been easy to program in, but you had to get it up and running first.  On Mac it&#8217;s been included in the OS for a few versions of Mac OS, on Linux it&#8217;s been as easy as &#8220;apt-get install rails&#8221; (or equivalent), and now on windows it&#8217;ll be as easy as &#8220;go to <a href="http://railsinstaller.org/">http://railsinstaller.org/</a>, download and clicky clicky&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkinginrails.com/2011/01/ruby-and-rails-on-windows-finally-simple/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Rails 3 Cheatsheets</title>
		<link>http://thinkinginrails.com/2011/01/rails-3-cheatsheets/</link>
		<comments>http://thinkinginrails.com/2011/01/rails-3-cheatsheets/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 04:44:37 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[Instructions]]></category>

		<guid isPermaLink="false">http://thinkinginrails.com/?p=640</guid>
		<description><![CDATA[Awesome work by Envy Labs (of Rails for Zombies and EnvyCasts fame) creating Ruby on Rails 3 Cheat Sheets. They look great, are well laid out, and are great to throw in your Rails PDF folder to look at when needed.]]></description>
			<content:encoded><![CDATA[<p>Awesome work by Envy Labs (of <a href="http://railsforzombies.org/">Rails for Zombies</a> and EnvyCasts fame) creating <a href="http://blog.envylabs.com/2010/12/rails-3-cheat-sheets/">Ruby on Rails 3 Cheat Sheets</a>.  They look great, are well laid out, and are great to throw in your Rails PDF folder to look at when needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkinginrails.com/2011/01/rails-3-cheatsheets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anatomy of A Ruby Gem</title>
		<link>http://thinkinginrails.com/2010/05/anatomy-of-a-ruby-gem/</link>
		<comments>http://thinkinginrails.com/2010/05/anatomy-of-a-ruby-gem/#comments</comments>
		<pubDate>Fri, 07 May 2010 03:01:22 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[Help]]></category>
		<category><![CDATA[Instructions]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://thinkinginrails.com/?p=431</guid>
		<description><![CDATA[If you&#8217;ve ever installed a Ruby gem off of gemcutter or github, you&#8217;ll know that you run the gem install &#60;gemname&#62; command and when it&#8217;s completed you magically have access to use it through &#8216;require &#60;gemname&#62;&#8217;.  If you&#8217;ve ever looked into the source you might want to have an idea of what goes where and [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever installed a Ruby gem off of gemcutter or github, you&#8217;ll know that you run the gem install &lt;gemname&gt; command and when it&#8217;s completed you magically have access to use it through &#8216;require &lt;gemname&gt;&#8217;.  If you&#8217;ve ever looked into the source you might want to have an idea of what goes where and how it all works.</p>
<p>First of all, I&#8217;m fairly new to this myself, so it&#8217;s very possible that I&#8217;ll miss something vital, please feel free to flame me in the comments, as long as you tell me where I messed up so I can fix it <img src='http://thinkinginrails.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span id="more-431"></span></p>
<p>Lets take a couple of examples.  One is a gem for dissecting XML feeds that I just discovered, <a href="http://github.com/pauldix/feedzirra">feedzirra</a>, the other is a bit more complex, <a href="http://github.com/injekt/cinch">Cinch</a>, the IRC micro-framework I was talking about a few days ago.  Starting with feedzirra, here&#8217;s the listing of the files and directories in the root of the gem, I&#8217;ll take them one by one.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">README.rdoc
README.textile
Rakefile
feedzirra.gemspec
lib/
spec/</pre></div></div>

<p><strong>README.*</strong></p>
<p>The first two are pretty obvious, they are the README files with GitHub (and others) automatically parses out and displays when you hit the main project page.  Here is a <a href="http://github.com/guides/readme-formatting">list of the README formats that github supports</a>, as well the order that it will display them in.  Here the author has included a README file as well as a README.textile (<a href="http://textile.thresholdstate.com/">texttile</a> is a simple markup language), and github displays the REAMDE.[something] first.</p>
<p><strong>Rakefile</strong></p>
<p><a href="http://rake.rubyforge.org/">Rake</a>, as you know is the ruby version of &#8220;make&#8221; the venerable Unix utility.  Inside the Rakefile you find a <a href="http://rake.rubyforge.org/files/doc/rakefile_rdoc.html">formatted</a> set of rules in the form of tasks and targets.  Hit <a href="http://onestepback.org/index.cgi/Tech/Rake/Tutorial/RakeTutorialRules.red">this tutorial</a> for some more details.  The short story is that there are targets (with prerequisite/dependency information) such as install, uninstall, and release, supporting functions if needed, and some boilerplate info (description, name, contact, etc).  The targets can be anything it seems, for example Feedzirra has a task for releasing and uploading a new release, whereas cinch just has an &#8216;install&#8217; task.  Rake is used a lot to help the creation of gems, but I don&#8217;t think that it&#8217;s used in the actual installation.</p>
<p><strong>[gemname].gemspec</strong></p>
<p>Here is the meat of it all, the gemspec file consists of the control information for the entire gem.  If you check out <a href="http://asciicasts.com/episodes/183-gemcutter-jeweler">this tutorial</a> you&#8217;ll see that it&#8217;s ruby code and can be created with a few utility scripts including Rake, and has some of the following information:</p>
<ul>
<li>Gem name and information (homepage, description)</li>
<li>Author information (email, etc)</li>
<li>Version and Date</li>
<li>Other gem dependencies</li>
<li>One or more boolean flags (ie: is there documentation that needs to be generated)</li>
<li>A file list of what files need to be installed</li>
<li>A list of executables of files that will be put in the bin directory when they&#8217;re installed</li>
</ul>
<p><strong>lib/ And Other Files or Directories</strong></p>
<p>Basically what&#8217;s left are directories of files that are going to be installed on your system.  Of course, &#8220;lib&#8221; isn&#8217;t always going to be there, but for most gems that are adding a new class into your ruby environment, it will be.  The gemspec file has the list of the files and directories that will actually be taken out of the gem and installed into your system.  There are different ways to specify these files in gemspec, as you&#8217;ll see by comparing the <strong>s.files</strong> directive in the <a href="http://github.com/injekt/cinch/blob/master/cinch.gemspec">Cinch gemspec</a> and the <a href="http://github.com/pauldix/feedzirra/blob/master/feedzirra.gemspec">Feedzirra gemspec</a>.</p>
<p>Inside the lib/ directory there will generally be one or two main files.  In Cinch you have:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">cinch/
cinch.rb</pre></div></div>

<p>This is the module that is loaded when you do a &#8216;require &#8220;cinch&#8221;&#8216; and the cinch/ directory has the supporting files.  The cinch.rb module file has a bunch of requires of &#8220;cinch/irc&#8221;, &#8220;cinch/rbase&#8221;, etc which are the sub-modules that it uses.  More on Modules vs Classes in a later post.</p>
<p><strong>spec/</strong></p>
<p>This will be the specs that the author has put in his source tree and includes so that other developers can look and use their tests.  Again, this isn&#8217;t going to <em>always</em> be there, but it seems to be very in vogue to do this whole &#8220;testing&#8221; thing, and including your spec or test directory is The Right Thing To Do.</p>
<p><strong>File Locations</strong></p>
<p>So when you run &#8216;gem install [foo]&#8216; where do the files go?  Lets use Cinch again for this one as it&#8217;s fairly simple.  Here&#8217;s a listing of the files that are in the source on github:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">./LICENSE
./lib/cinch.rb
./lib/cinch/irc
./lib/cinch/irc/parser.rb
./lib/cinch/* [ more library module files ]
./examples/hello.rb
./examples/* [ more example files ]
./README.rdoc
./spec/irc/parser_spec.rb
./spec/* [ more specs ]
./Rakefile
./cinch.gemspec</pre></div></div>

<p>(Note some of the directories are abbreviated).</p>
<p>When you do a <strong>gem install</strong> the files moved into the path defined in $GEM_HOME thusly:</p>
<pre>cinch/lib           =&gt; $GEM_HOME/gems/cinch-0.2.6/lib
cinch/examples      =&gt; $GEM_HOME/gems/cinch-0.2.6/examples
[...]
cinch/README.rdoc   =&gt; $GEM_HOME/gems/cinch-0.2.6/README.rdoc
                    =&gt; $GEM_HOME/doc/cinch-0.2.6/ri/*
                    =&gt; $GEM_HOME/doc/cinch-0.2.6/rdoc/*
</pre>
<p>Nothing <em>hugely</em> interesting, files are basically just moved into your gem home directory under a directory named with the name and version of the gem you&#8217;re installing.  Note that the doc/*/ri and doc/*/rdoc files are auto-created when the gem install runs, if you don&#8217;t pass the &#8211;no-ri or &#8211;no-rdoc flags of course.  The internal magic in rubygems and ruby allow your programs to find the gems when they are &#8216;required&#8217;.</p>
<p><strong>How to Examine A Gem</strong></p>
<p>One of the nicest ways to play with these things, and what I did was  to use <a href="http://rvm.beginrescueend.com">RVM</a> and then doing a gem  install, as well as using git clone to pull down the source files from  github.  RVM, combined with it&#8217;s great <a href="http://rvm.beginrescueend.com/gemsets/">gemset support</a>, is  a great tool and makes it really easy to add, remove, and play with no  fear of mucking things up.</p>
<p><strong>Conclusion</strong></p>
<p>So that&#8217;s about it for the normal library gems that you&#8217;ll find on github.  Hopefully you now understand a bit more about how a gem is structured and what happens when you install and use gems, and how they will interact with each other.  I found lots of resources out there, including some great stuff on how to create your own gems, gemspec files, and so on, listed below.</p>
<p><strong>Additional Reading</strong></p>
<ul>
<li><a href="http://docs.rubygems.org/read/chapter/5">http://docs.rubygems.org/read/chapter/5</a></li>
<li><a href="http://rubygems.org/pages/gem_docs">http://rubygems.org/pages/gem_docs</a></li>
<li><a href="http://railscasts.com/episodes/135-making-a-gem">http://railscasts.com/episodes/135-making-a-gem</a></li>
<li><a href="http://asciicasts.com/episodes/183-gemcutter-jeweler">http://asciicasts.com/episodes/183-gemcutter-jeweler</a></li>
<li><a href="http://buzaz.com/index.php/2010/01/03/how-to-build-a-ruby-gem/">http://buzaz.com/index.php/2010/01/03/how-to-build-a-ruby-gem/</a></li>
<li><a href="http://docs.rubygems.org/read/chapter/20">http://docs.rubygems.org/read/chapter/20</a></li>
<li><a href="http://yehudakatz.com/2010/04/02/using-gemspecs-as-intended/">http://yehudakatz.com/2010/04/02/using-gemspecs-as-intended/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://thinkinginrails.com/2010/05/anatomy-of-a-ruby-gem/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Evolving A Simple Twitter to Blog Ruby Program Part 1</title>
		<link>http://thinkinginrails.com/2010/05/evolving-a-simple-twitter-to-blog-ruby-program-part-1/</link>
		<comments>http://thinkinginrails.com/2010/05/evolving-a-simple-twitter-to-blog-ruby-program-part-1/#comments</comments>
		<pubDate>Wed, 05 May 2010 04:14:57 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Instructions]]></category>

		<guid isPermaLink="false">http://thinkinginrails.com/?p=365</guid>
		<description><![CDATA[In a "quick" and dirty exercise I built a little ruby program to grab my twitter posts and colate them into a list for posting a "tweets of the week" type blog post.  It was a lot more about figuring out how to do it than the actual output (I'd hope you just follow me on twitter than rely on me posting my tweets here).  Tonight at the FV.rb meeting @dkubb helped me a lot in pointing out some glaring non-rubyisms and I thought that going through some of the changes might help others moving from "old school" programming (structured, functional, perl-y) to "new hotness" programming (object oriented, yeilds, and awesomeness).]]></description>
			<content:encoded><![CDATA[<p>In a &#8220;quick&#8221; and dirty exercise I built a little ruby program to grab my twitter posts and colate them into a list for posting a &#8220;tweets of the week&#8221; type blog post.  It was a lot more about figuring out how to do it than the actual output (I&#8217;d hope you just <a href="http://twitter.com/thinkinginrails">follow me</a> on twitter than rely on me posting my tweets here).  Tonight at the FV.rb meeting <a href="http://twitter.com/dkubb">@dkubb</a> helped me a lot in pointing out some glaring non-rubyisms and I thought that going through some of the changes might help others moving from &#8220;old school&#8221; programming (structured, functional, perl-y) to &#8220;new hotness&#8221; programming (object oriented, yeilds, and awesomeness).</p>
<p>I started out with <a href="http://gist.github.com/382571/5c87bd0bd5c59bef4d00c1357420d9cfac309699">this code</a> in a gist.  Nothing hugely bad, it pulls in either a URL or a file, parses the XML for the status updates, and for each one does some HTML replacement (@user, #hash, and URLs get auto-linked) and then spits out some HTML that can be copied and pasted into a blog entry.</p>
<p><strong>Starting Off</strong></p>
<p>The first step was figuring out how to parse the XML.   A bit of googling <a href="http://www.rubyinside.com/ruby-xml-performance-benchmarks-1641.html">found</a> <a href="http://railstips.org/blog/archives/2008/08/11/parsing-xml-with-ruby/">some</a> possibilities.  <a href="http://hpricot.com/">Hpricot</a>, <a href="http://libxml.rubyforge.org/">libxml-ruby</a>, and <a href="http://rdoc.info/projects/brynary/nokogiri">Nokogiri</a>.  The first post I saw noted that libxml-ruby was the fastest, which makes sense as it&#8217;ll be pretty close to the bare metal C libraries, so I took a run with that.  Not great success, the biggest challenge was figuring out how Ruby dealt with XML structure.  There was a lot of mucking around in IRB.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p249 <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'xml'</span>
 <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p249 <span style="color:#006600; font-weight:bold;">&gt;</span> parser = <span style="color:#6666ff; font-weight:bold;">XML::Parser</span>.<span style="color:#9900CC;">file</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'twitter.xml'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#008000; font-style:italic;">#&lt;LibXML::XML::Parser:0x101170140 @context=#&lt;LibXML::XML::Parser::Context:0x101170168&gt;</span>
ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p249 <span style="color:#006600; font-weight:bold;">&gt;</span> doc = parser.<span style="color:#9900CC;">parse</span>
<span style="color:#008000; font-style:italic;"># snip xml spew to STDOUT</span>
ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p249 <span style="color:#006600; font-weight:bold;">&gt;</span> doc.<span style="color:#9966CC; font-weight:bold;">class</span>
 <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">LibXML::XML::Document</span>
<span style="color:#008000; font-style:italic;"># Hmm.... does find work?</span>
ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p249 <span style="color:#006600; font-weight:bold;">&gt;</span> s = doc.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'/status'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#008000; font-style:italic;">#&lt;LibXML::XML::XPath::Object:0x1018ff398&gt;</span>
ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p249 <span style="color:#006600; font-weight:bold;">&gt;</span> s.<span style="color:#9900CC;">methods</span>
<span style="color:#008000; font-style:italic;"># snip list of methods, and searching for what to do</span>
ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p249 <span style="color:#006600; font-weight:bold;">&gt;</span> s.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>node<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">puts</span> node.<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
 <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span>
ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p249 <span style="color:#006600; font-weight:bold;">&gt;</span> s.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>node<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">puts</span> node.<span style="color:#9900CC;">inspect</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
 <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span>
<span style="color:#008000; font-style:italic;"># WTF? OK, so what now then?</span></pre></div></div>

<p>It was a bit frustrating, though probably mostly because I just didn&#8217;t grok how the XML was being represented internally, and thinking of it more like a Perl hash-of-hashes than whatever libxml-ruby was using.  So I moved on.  (Ironically while re-doing some of this for this article I went back and was running the commands figuring now I would get it, and failed miserably <img src='http://thinkinginrails.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Next I looked at <a href="http://hpricot.com/">Hpricot</a>, but the syntax in the readme and examples scared me away.</p>
<p><strong>Starting Progress on the First Iteration</strong></p>
<p>Someone at work suggested that Nokogiri was the way to go, and realizing that parsing a few kb of XML probably wasn&#8217;t going to run me into any performance issues, I took a run at it with this.  I soon found that having a static XML file would be the easiest for testing, so I saved twitter.xml in the same directory as I was running IRB out of and played some more.</p>
<p>Much better.  Then to find out to get a list of the statuses:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p249 <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'nokogiri'</span>
 <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p249 <span style="color:#006600; font-weight:bold;">&gt;</span> doc = <span style="color:#6666ff; font-weight:bold;">Nokogiri::XML</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'twitter.xml'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#008000; font-style:italic;"># snip</span>
ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p249 <span style="color:#006600; font-weight:bold;">&gt;</span> doc.<span style="color:#9966CC; font-weight:bold;">class</span>
 <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">Nokogiri::XML::Document</span>
ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p249 <span style="color:#006600; font-weight:bold;">&gt;</span> doc.<span style="color:#9900CC;">xpath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'/status'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p249 <span style="color:#006600; font-weight:bold;">&gt;</span> doc.<span style="color:#9900CC;">xpath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'//status'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#008000; font-style:italic;"># snip lots more xml spew and more testing until...</span>
ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p249 <span style="color:#006600; font-weight:bold;">&gt;</span> doc.<span style="color:#9900CC;">xpath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'//status'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>node<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">puts</span> node.<span style="color:#9900CC;">xpath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;.//text&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">content</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;"># snip lovely output of each of the tweets in the xml file</span></pre></div></div>

<p>Ok, so now I could run &#8220;.each()&#8221; on this, having discovered that the xpath() function basically allowed me to get a list of XML nodes with that path, and <em>then</em> I could get a list of node data from that, remembering to use the &#8220;start from current node&#8221; syntax (using the &#8216;.&#8217; to represent the current location in the tree).</p>
<p>The next steps were (relatively) easy.  Looping through each status, get some information (time, status ID, content, etc), format that into HTML, find and implement a couple of &#8220;convert @user to an HTML link&#8221; bits of code I <a href="http://stackoverflow.com/questions/2034580/i-am-creating-a-twitter-clone-in-ruby-on-rails-how-do-i-code-it-so-that-the">found online</a>, and voila, first iteration was completed and working.</p>
<p><strong>Now With Some Expert Advice</strong></p>
<p>So after reading the <a href="http://blog.sirupsen.dk/me/what-i-wish-a-ruby-programmer-had-told-me-one-year-ago/">What I wish I had been told a year ago</a> post, I figured the next stage was to convert it to a class, make it more ruby-y, and give it some tests.  Dan Kubb of <a href="http://datamapper.org/">DataMapper</a> fame thankfully answered my question to help and moved me on to <a href="https://gist.github.com/382571/5c87bd0bd5c59bef4d00c1357420d9cfac309699">this current version</a> with some helpful advice.</p>
<p>I&#8217;ll continue this later on this week with Part 2, in which I iterate into more awesomeness!</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkinginrails.com/2010/05/evolving-a-simple-twitter-to-blog-ruby-program-part-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Rails Authentication In a Gist</title>
		<link>http://thinkinginrails.com/2010/03/rails-authentication-in-a-gist/</link>
		<comments>http://thinkinginrails.com/2010/03/rails-authentication-in-a-gist/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 18:09:35 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Instructions]]></category>

		<guid isPermaLink="false">http://thinkinginrails.com/?p=114</guid>
		<description><![CDATA[I&#8217;ve been trying to get some more use onto my github account, and to this end I&#8217;ve copied my work on the rails authentication (a rip from Adian&#8217;s work, he gets full credit) over to this gist.  Basically this is just exactly what Aidan did originally, but in a more cut-and-paste friendly format.  I&#8217;ve also [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying to get some more use onto my github account, and to this end I&#8217;ve copied my work on the rails authentication (a rip from <a href="http://www.aidanf.net/rails_user_authentication_tutorial">Adian&#8217;s work</a>, he gets full credit) over to <a href="http://gist.github.com/333110">this gist</a>.  Basically this is just exactly what Aidan did originally, but in a more cut-and-paste friendly format.  I&#8217;ve also included a couple of minor fixes to it (ie: preventing the user password from being nuked on save and some other minor changes that were found in the comments on the original blogpost).  I also haven&#8217;t included any of the tests (bad Alan, I know), but my thought is that you&#8217;re going to have your own test system, be it Rspec, Cucumber, or whatever) and putting in some tests there might be counter-productive if you&#8217;re already rocking with [insert your testing framework here].</p>
<p>The idea really is just that the <em>next</em> time I need to put in some authentication I don&#8217;t have to search as far, or go through as long a page, but can just grab <a href="http://gist.github.com/333110">the gist</a>, copy and paste the needed chunks, and go.</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkinginrails.com/2010/03/rails-authentication-in-a-gist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Challenge of Learning Ruby</title>
		<link>http://thinkinginrails.com/2009/05/the-challenge-of-learning-ruby/</link>
		<comments>http://thinkinginrails.com/2009/05/the-challenge-of-learning-ruby/#comments</comments>
		<pubDate>Sat, 09 May 2009 19:05:40 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Instructions]]></category>

		<guid isPermaLink="false">http://thinkinginrails.com/?p=32</guid>
		<description><![CDATA[One of the biggest challenges I have as a Perl programmer is dealing with the change in the underlying language that Rails is written in, namely, Ruby.  To help with this I&#8217;m working myself through Project Euler to do a couple of things Force myself to work through problems in Ruby After solving the problems, [...]]]></description>
			<content:encoded><![CDATA[<p>One of the biggest challenges I have as a Perl programmer is dealing with the change in the underlying language that Rails is written in, namely, Ruby.  To help with this I&#8217;m working myself through Project Euler to do a couple of things</p>
<ul>
<li>Force myself to work through problems in Ruby</li>
<li>After solving the problems, see how others did them</li>
</ul>
<p>The last item is the most important.  I generally start off in a very perl-ish, procedural way.  When the answer arrives it&#8217;s a real eye opener to see how others solve the issues.  For example, for one problem after solving it in what I thought was a fairly elegant way (a couple of short functions), seeing the first Ruby based solution in the forums the programmer had used a quick <a href="http://en.wikipedia.org/wiki/Monkey_patch">Monkey Patch</a> (modification of the base Integer class in this case) to simply add a function that did what he wanted.  I had never even thought of this!  I knew the capabilities of Ruby to do this, but my brain just hadn&#8217;t triggered the idea that this was a good solution.</p>
<p>The pros and cons of Monkey Patching are a discussion for another day of course <img src='http://thinkinginrails.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I&#8217;m fairly proud of myself, I have worked through some of the problems and even just wrote the following line of code&#8230; on purpose!</p>
<p><code>(1..100).inject { |s,i| s*i }.to_s.split(//).inject(0) { |s,n| s + n.to_i }</code></p>
<p>I admit that my perl-ish nature of doing it all on one line came out a bit <img src='http://thinkinginrails.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   The <em>actual</em> solution that I came up with was a bit nicer of course!</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkinginrails.com/2009/05/the-challenge-of-learning-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Ins and Outs of Serving Rails</title>
		<link>http://thinkinginrails.com/2009/05/the-ins-and-outs-of-serving-rails/</link>
		<comments>http://thinkinginrails.com/2009/05/the-ins-and-outs-of-serving-rails/#comments</comments>
		<pubDate>Sat, 02 May 2009 00:16:33 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Instructions]]></category>

		<guid isPermaLink="false">http://thinkinginrails.com/?p=24</guid>
		<description><![CDATA[One of the biggest failures I found starting in Rails was the lack of a standard for hosting.  In the mod_perl or php world, the standard apache distribution has everything needed built in to the standard distribution, and you&#8217;d be hard pressed to find a hosting system (of any size) that doesn&#8217;t have them. Rails [...]]]></description>
			<content:encoded><![CDATA[<p>One of the biggest failures I found starting in Rails was the lack of a standard for hosting.  In the <a href="http://perl.apache.org">mod_perl</a> or <a href="http://php.net">php</a> world, the standard apache distribution has everything needed built in to the standard distribution, and you&#8217;d be hard pressed to find a hosting system (of any size) that doesn&#8217;t have them.</p>
<p>Rails on the other hand, seemed to have a boatload of ways to serve itself.  There doesn&#8217;t seem to be a &#8220;standard&#8221; webserver.  You have <a href="http://mongrel.rubyforge.org/">mongrel</a>, <a href="http://nginx.net/">nginx</a>, phusion passenger (<a href="http://www.modrails.com/">mod_rails</a>), <a href="http://www.lighttpd.net/">lighttp</a>&#8230; the list goes on.  And it doesn&#8217;t seem that there&#8217;s an accepted &#8220;proper&#8221; way to do the webserving yet.  Maybe it&#8217;s a case of different tools for different cases, maybe it&#8217;s just a symptom of a system that&#8217;s relatively young (compared to the apache/perl/php world).</p>
<p><span id="more-24"></span></p>
<p>Obviously the build in webserver (<tt>ruby script/server</tt>) will always be there, but if you&#8217;ve got your first app up and ready, and your hosting provider either doesn&#8217;t supply rails hosting as an option, or their setup isn&#8217;t up to the task I discovered an interesting (and most importantly, <strong>free</strong>) solution.</p>
<p>Check out <a href="http://heroku.com/">Heroku</a>.  It&#8217;s a free, online hosting system with a fairly unique method of using git to allow you to simply run &#8220;<tt>git push</tt>&#8221; in your app directory and have any changes pushed up to their hosting cloud.  Now granted, they are a commercial company and you only get the equivalent of the lowest level of hosting (a &#8220;Blossom&#8221; plan with 5mb of disk space), but this is perfectly adequate for a personal project or learning application.  And again, it&#8217;s <em>free</em> <img src='http://thinkinginrails.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Dead Programmer Society has <a href="http://deadprogrammersociety.blogspot.com/2009/04/heroku-why-havent-i-been-using-you-till.html">a nice write up on the whole deal</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkinginrails.com/2009/05/the-ins-and-outs-of-serving-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

