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

<channel>
	<title>trapdoor1</title>
	<atom:link href="http://blog.trapdoor1.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.trapdoor1.net</link>
	<description>rails, ruby, supercollider, dsp</description>
	<pubDate>Wed, 09 Jul 2008 10:28:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>Quick testing of ActiveRecord validations in RSpec</title>
		<link>http://blog.trapdoor1.net/2008/07/09/quick-testing-of-activerecord-validations-in-rspec/</link>
		<comments>http://blog.trapdoor1.net/2008/07/09/quick-testing-of-activerecord-validations-in-rspec/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 09:57:05 +0000</pubDate>
		<dc:creator>robin</dc:creator>
		
		<category><![CDATA[RSpec]]></category>

		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[custom matcher]]></category>

		<category><![CDATA[validations]]></category>

		<guid isPermaLink="false">http://blog.trapdoor1.net/?p=54</guid>
		<description><![CDATA[ActiveRecord&#8217;s validations are a convenient way to test and control the state of objects before they hit the database.
Validations are themselves a presumably well-tested part of Ruby on Rails, but their usage in an application significantly changes the behaviour of your objects.
This means they should be spec&#8217;d like anything else.
Spec&#8217;ing out every single attribute on [...]]]></description>
			<content:encoded><![CDATA[<p>ActiveRecord&#8217;s validations are a convenient way to test and control the state of objects before they hit the database.</p>
<p>Validations are themselves a presumably well-tested part of Ruby on Rails, but their usage in an application significantly changes the behaviour of your objects.</p>
<p><i>This means they should be spec&#8217;d like anything else.</i></p>
<p>Spec&#8217;ing out every single attribute on every single model is pretty repetitive though. Yesterday I rolled my own custom matcher to speed up this task. It takes advantage of the fact that I follow the convention of using a <code>valid_attributes</code> method somewhere in my model&#8217;s spec, which I use to create a basic object for testing. For example:</p>
<pre name="code" class="ruby">
describe "Comment" do
&nbsp;&nbsp;def valid_attributes
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:commentable_type => 'Item',
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:commentable_id => 1,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:content => "This is a comment!",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:user_id => 1
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;end
&nbsp;&nbsp;
&nbsp;&nbsp;before(:each) do
&nbsp;&nbsp;&nbsp;&nbsp;@comment = Comment.new(valid_attributes)
&nbsp;&nbsp;end
&nbsp;&nbsp;
&nbsp;&nbsp;it "should ..."
end
</pre>
<p>My custom matcher allows me to add a single spec which ensures that the comment validates with exactly these attributes, and no less.</p>
<pre name="code" class="ruby">
&nbsp;&nbsp;it "should validate with exactly the specified attributes" do
&nbsp;&nbsp;&nbsp;&nbsp;@comment.should validate_with_exactly(valid_attributes)
&nbsp;&nbsp;end
</pre>
<p>The spec will fail - with an readable error message - if <b>either</b>:</p>
<ul>
<li>The object is <b>invalid</b> with all the specified attribues</li>
<li><b>Any one</b> of the attributes is missing and the object is <b>valid</b></li>
</ul>
<p>The spec code is available at <a href="http://pastie.org/230565">http://pastie.org/230565</a> - pastie it into your <code>spec_helper.rb</code>.</p>
<p>This is still so hot off the press it&#8217;s positively steaming. Do you have any comments, bug reports or suggestions?</p>
 <img src="http://blog.trapdoor1.net/wp-content/plugins/feed-statistics.php?view=1&post_id=54" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.trapdoor1.net/2008/07/09/quick-testing-of-activerecord-validations-in-rspec/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Rubinius&#8217; lurking presence continues to be felt</title>
		<link>http://blog.trapdoor1.net/2008/05/11/rubinius-lurking-presence-continues-to-be-felt/</link>
		<comments>http://blog.trapdoor1.net/2008/05/11/rubinius-lurking-presence-continues-to-be-felt/#comments</comments>
		<pubDate>Sun, 11 May 2008 20:08:35 +0000</pubDate>
		<dc:creator>robin</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[merb]]></category>

		<category><![CDATA[rubinius]]></category>

		<guid isPermaLink="false">http://blog.trapdoor1.net/?p=41</guid>
		<description><![CDATA[Merb now seems to be tentatively running on Rubinius, the fledgling Ruby virtual machine. I&#8217;m watching both of these projects with real interest, although I have nowhere near enough free time to put either through their paces just yet (neither are close to production levels of usability at this point in any case).
It&#8217;s good to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://merbivore.com/">Merb</a> now seems to be <a href="http://metaclass.org/2008/5/10/merb-on-rubinius">tentatively running</a> on <a href="http://rubini.us/">Rubinius</a>, the fledgling Ruby virtual machine. I&#8217;m watching both of these projects with real interest, although I have nowhere near enough free time to put either through their paces just yet (neither are close to production levels of usability at this point in any case).</p>
<p>It&#8217;s good to see Ruby&#8217;s boundaries being pushed, though. And there&#8217;s a reasonable chance that one or both of these projects could be the future.</p>
<p>And of course, <strong>Rubinius on Rails.</strong>..</p>
<p>That will really be interesting.</p>
 <img src="http://blog.trapdoor1.net/wp-content/plugins/feed-statistics.php?view=1&post_id=41" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.trapdoor1.net/2008/05/11/rubinius-lurking-presence-continues-to-be-felt/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Why I am switching to test-driven development</title>
		<link>http://blog.trapdoor1.net/2008/05/10/why-i-am-switching-to-test-driven-development/</link>
		<comments>http://blog.trapdoor1.net/2008/05/10/why-i-am-switching-to-test-driven-development/#comments</comments>
		<pubDate>Sat, 10 May 2008 22:49:54 +0000</pubDate>
		<dc:creator>robin</dc:creator>
		
		<category><![CDATA[RSpec]]></category>

		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://blog.trapdoor1.net/?p=38</guid>
		<description><![CDATA[I am going to change the way I code.
My working pattern is, roughly, as follows:

 Sketch a basic method implementation
Test it manually
Fine tune the code, improve implementation
Further manual testing, fix a few bugs
Write a test
Done! Make a cup of coffee.

Is there anything so bad about this process? I write a test, so I get one [...]]]></description>
			<content:encoded><![CDATA[<p>I am going to change the way I code.</p>
<p>My working pattern is, roughly, as follows:</p>
<ol>
<li> Sketch a basic method implementation</li>
<li>Test it manually</li>
<li>Fine tune the code, improve implementation</li>
<li>Further manual testing, fix a few bugs</li>
<li>Write a test</li>
<li>Done! Make a cup of coffee.</li>
</ol>
<p>Is there anything so bad about this process? I write a test, so I get one gold-star. And there&#8217;s nothing wrong with the end results: I write good code, which usually works. But I think I could work better. Every time I&#8217;ve written a model or controller for as long as I can remember, a little voice in my head asks: &#8220;<strong>Why haven&#8217;t you written the test first&#8230;?</strong>&#8221;</p>
<p>Anybody else get the same little voice? I suspect there&#8217;s a few of you out there.</p>
<p>The more I&#8217;ve learnt about TDD, the more I&#8217;ve wanted to practice it. At first, it just seemed like a way of ensuring thorough test coverage, but that is actually just a sweet, sweet bonus. For me, TDD is more about changing my entire mindset when it comes to coding. The benefits promise to run deeper than may first appear obvious.</p>
<p>Sure, testing first will remind me to focus on what I want my code to do, <em>before</em> I start coding. This is valuable, yes - and I can see it helping me avoid a few refactoring/start-from-scratch sessions when my brain hasn&#8217;t quite been in gear - but I don&#8217;t believe that it will much improve my resulting finished code, so much as make the process of getting there a more efficient.</p>
<p>The more precious benefit, is that the pre-written tests will tell me exactly when to <em>stop</em> - and that&#8217;s a time when it&#8217;s a lot easier to trip up. Especially a day later, or a month later. The habit of testing first will prompt me to keep my methods small and manageable. Small and manageable in the short-term, equates to easy-to-maintain and stable in the long-term. A method of working which virtually <em>obliges</em> me to create manageable, bug-free code? <em>And</em> as good as guarantees a working stack of tests across my application?</p>
<p>There&#8217;s a whole host of other good reasons too, some of which I am perhaps yet to fully appreciate, but enough already. I am convinced.</p>
<p>So, why aren&#8217;t I doing it? My only problem is <strong>discipline</strong>. That&#8217;s going to change.</p>
<h3>Test-unit Zappa</h3>
<p>How will I switch to TDD? Firstly, I will drop <a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html">Test::Unit</a> and make the switch to <a href="http://rspec.info/">RSpec</a>.</p>
<p>Why switch? After all, the Test::Unit framework is a proven system in itself. It&#8217;s been shown to be more than capable of providing in-depth test coverage in complex applications, and is also usable within a strictly test-driven environment. What&#8217;s more, it&#8217;s true to say that there&#8217;s little testing that can be done with RSpec, that can&#8217;t already be done, one way or the other, using Test::Unit.</p>
<p>Isn&#8217;t switching from a system I am already well familiar with, simply going to be a short-term hindance - and offer questionable benefits in the long-term?</p>
<p>There are two stand-out reasons. Firstly, working with a different testing framework will force me to throw out my old habits, and hopefully help me to break my old routines and shake up my testing in the way that I want. Old habits die hard, and sometimes need a little persuasion.</p>
<p>Secondly - and perhaps even more importantly - it&#8217;s about changing the the language in which I write tests. RSpec&#8217;s descriptive idioms - typically written as <code>something.<em>should</em>_have</code> - are forward-looking, and cry out to be written and defined <em>before</em> the method they test. This is quite different to Test::Unit, which really encourages working the other way around.</p>
<p>As Josh Stephenson highlights <a href="http://fr.ivolo.us/posts/rspec-tutorial-part-1">here</a>:</p>
<blockquote><p>Just as sociologists have postulated that the language we use to express the world around us directly affects the way we interpret it, the language we use to test applications directly affects the way we develop them.</p></blockquote>
<p>So RSpec will force me to throw out both my testing routines, and my vocabulary. I can&#8217;t do much more to create a catalyst for change.</p>
<p>Of course, I will be monitoring my work-flow, productivity and the resulting code carefully. If, after a reasonable period it is clear to me that TDD is not working - back I can go. But a decent spell of practicing TDD, a good level of familiarity - a fair test, so to speak - is going to be needed before I can conquer that little voice in my head, one way or the other.</p>
<p>In due course, I will post my progress here.</p>
<h4>References/Further reading</h4>
<p><a href="http://www.oreillynet.com/pub/a/ruby/2007/08/09/behavior-driven-development-using-ruby-part-1.html?page=1">http://www.oreillynet.com/pub/a/ruby/2007/08/09/behavior-driven-development-using-ruby-part-1.html?page=1</a></p>
<p><a href="http://www.agiledata.org/essays/tdd.html">http://www.agiledata.org/essays/tdd.html</a></p>
<p><a href="http://blog.daveastels.com/files/BDD_Intro.pdf">http://blog.daveastels.com/files/BDD_Intro.pdf</a></p>
 <img src="http://blog.trapdoor1.net/wp-content/plugins/feed-statistics.php?view=1&post_id=38" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.trapdoor1.net/2008/05/10/why-i-am-switching-to-test-driven-development/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ruby, from the perspective of SuperCollider</title>
		<link>http://blog.trapdoor1.net/2008/05/07/ruby-from-the-perspective-of-supercollider/</link>
		<comments>http://blog.trapdoor1.net/2008/05/07/ruby-from-the-perspective-of-supercollider/#comments</comments>
		<pubDate>Wed, 07 May 2008 19:35:53 +0000</pubDate>
		<dc:creator>robin</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[SuperCollider]]></category>

		<category><![CDATA[five things]]></category>

		<guid isPermaLink="false">http://blog.trapdoor1.net/?p=33</guid>
		<description><![CDATA[SuperCollider? It&#8217;s a programming environment designed for live digital signal processing, audio manipulation and algorithmic composition - making music, in other words. It is also contains a fully-fledged, dynamic, object-oriented language strongly influenced by both Smalltalk and functional programming, and as such it has a fair bit in common with Ruby.
There&#8217;s nothing like using two [...]]]></description>
			<content:encoded><![CDATA[<p>SuperCollider? It&#8217;s a programming environment designed for live digital signal processing, audio manipulation and algorithmic composition - making music, in other words. It is also contains a fully-fledged, dynamic, object-oriented language strongly influenced by both Smalltalk and functional programming, and as such it has a fair bit in common with Ruby.</p>
<p>There&#8217;s nothing like using two languages a lot (which I do) to get you comparing their finer details. Here&#8217;s what I have come to see differently about Ruby from coding in SC, and a few things I miss in Ruby that are present in SC. Maybe I&#8217;ll follow it up in the future, and do it the other way round.</p>
<h3>Punctuation <em>can</em> be beautiful after all</h3>
<p>Amongst a beginning Ruby programmer&#8217;s first acts, still flushed with the excitement of escaping from Java or PHP, will be to quite consciously <em>throw away </em>the habit of finishing each line of code with a semi-colon. And why not? They bugged me for years too, being obviously unnecessary in 99% of cases, cluttering up the page and and causing countless exceptions and failed builds when misplaced. And basically, for no good reason.</p>
<p>How many semi-colons do you see in Ruby code? Not a whole lot, in my experience. It&#8217;s almost like they&#8217;re omitted in order to somehow <em>punish</em> Java, perhaps deservedly.</p>
<p>SuperCollider requires the semi-colon at the end of (most) lines, and I used to feel it a bit of a pain. But semi-colons have kind of grown on me. Perhaps it&#8217;s because of SC&#8217;s strong functional programming paradigms, which means that it&#8217;s easier to chain multiple messages together than Ruby, even while splitting them across multiple lines.</p>
<pre class="ruby" name="code">SCWindow.new("A window!", Rect(20, 20, 300, 300))
&nbsp;&nbsp;&nbsp;&nbsp;.alwaysOnTop_( true )
&nbsp;&nbsp;&nbsp;&nbsp;.onClose_{ "Goodbye!".postln }
&nbsp;&nbsp;&nbsp;&nbsp;.userCanClose_( false )
&nbsp;&nbsp;&nbsp;&nbsp;.front
&nbsp;&nbsp;&nbsp;&nbsp;;</pre>
<p>Most people seem to hide the semi-colon away. I prefer to give it pride of place, hanging it off the end of the indentation like a tear-drop.</p>
<p>The semi-colon is dead&#8230; Long live the semi-colon.</p>
<h3>Syntactic sugar, SC style</h3>
<p>Assuming iteration over a list - or range - makes a lot of sense. Actually, this isn&#8217;t syntactic sugar at all - just sensible proxying of messages - but it certainly feels like it.</p>
<h5>Ruby:</h5>
<pre class="ruby" name="code">(1..10).to_a.collect{ |num| num.squared }
# Ruby version &gt;= 1.9
(1..10).to_a.collect(&amp;:squared)

#=&gt; [ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81 ]</pre>
<h5>SuperCollider:</h5>
<pre class="ruby" name="code">(1..10).squared

#=&gt; [ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81 ]</pre>
<p>Also worth a mention is SC&#8217;s ! notation, as an alternative to Object#dup. This can often be used to fill an array.</p>
<h5>Ruby</h5>
<pre class="ruby" name="code">Array.new(10){ rand(10) }</pre>
<h5>SuperCollider</h5>
<pre class="ruby" name="code">{ 10.rand } ! 10</pre>
<h3>Partial application</h3>
<p>Partial application allows the creation of functions from implicit input data - that is, call a method sending less than the required number of arguments. This is a trick picked up from functional languages such as Haskell. There, however, it&#8217;s better known as currying.</p>
<p>It can be (vaguely) comparable, in effect, to <code>Symbol#to_proc</code> in Rails (and Ruby 1.9), but is endlessly more flexible and powerful.</p>
<p>Each pair of lines are equivalent:</p>
<pre class="ruby" name="code">(1..10).collect{ |number| number.postln };
(1..10).collect(_.postln);

(1..10).collect {|x| Polar(x, pi) };
(1..10).collect(Polar(_, pi));</pre>
<p>There are ways to <a href="http://moonbase.rydia.net/mental/blog/programming/currying-in-ruby">approximate this kind of thing</a> in Ruby, but none which look (to me) remotely as elegant.</p>
<p>Currying is cool.</p>
<h3>Instant API</h3>
<p>Why does coding in SC seem so quick and easy?</p>
<p>Maybe, its partly down to the speed of access to  the language documentation. And it really is quick. Not sure how to scan each item of array? Just type <code>Array</code>, select it and hit CMD-D - up pops the SC documentation for Array class. Unsure of where a method you are calling is implemented in the class hierarchy? Select it and hit CMD-Y, and up pops a list of classes where the method is implemented, including extensions and plugins.</p>
<p>And best of all, select the name of any class and hit CMD-J. There in front of you is the source code for that actual class.</p>
<p>Now, it would be unfair to use this as a criticism of Ruby, as SC has an integrated editing environment which makes this sort of thing possible to build in as standard. But anybody who created a Ruby version of this system, perhaps as a plugin for TextMate, would be an instant superstar in my eyes, and I would think a good few others too.</p>
<h3>My conclusions&#8230;</h3>
<p>I am increasingly aware of how much Smalltalk is responsible for, and more and more interested in getting to know it a bit better in itself. Learning a new language never did anybody any harm.</p>
 <img src="http://blog.trapdoor1.net/wp-content/plugins/feed-statistics.php?view=1&post_id=33" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.trapdoor1.net/2008/05/07/ruby-from-the-perspective-of-supercollider/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Under the hood: Ruby&#8217;s global variables</title>
		<link>http://blog.trapdoor1.net/2008/05/04/under-the-hood-rubys-global-variables/</link>
		<comments>http://blog.trapdoor1.net/2008/05/04/under-the-hood-rubys-global-variables/#comments</comments>
		<pubDate>Sun, 04 May 2008 20:18:52 +0000</pubDate>
		<dc:creator>robin</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[global variables]]></category>

		<guid isPermaLink="false">http://blog.trapdoor1.net/?p=31</guid>
		<description><![CDATA[Tinkering in irb earlier, I ran this line of code.

global_variables.each{ &#124;var&#124; puts var + ": " + eval(var).inspect }

Ruby&#8217;s global variables - I have long been aware of their existence in the background, but I hadn&#8217;t realised quite how many are initialized by default. What are they all for - and what cool metaprogramming tricks [...]]]></description>
			<content:encoded><![CDATA[<p>Tinkering in <code>irb</code> earlier, I ran this line of code.</p>
<pre name="code" class="ruby">
global_variables.each{ |var| puts var + ": " + eval(var).inspect }
</pre>
<p>Ruby&#8217;s global variables - I have long been aware of their existence in the background, but I hadn&#8217;t realised quite how many are initialized by default. What are they all for - and what cool metaprogramming tricks can I use them for?</p>
<p>I actually use one of these variables very often, and it deserves a special mention. <code>$!</code> points to the most recently raised exception, and is a useful shortcut in many contexts. A lot of the others promise to be most useful in a shell/CGI script environment - but it&#8217;s good to know they&#8217;re there, and a little peek under the hood of Ruby usually proves instructional.</p>
<p>Here&#8217;s the global variables initialized by default on my system (Ruby 1.8.6 on OSX 10.5) - where I have some idea what they refer to, I&#8217;ve added that too. </p>
<table class="tabbed" style="height: 24px;" border="0" width="589">
<tbody>
<tr>
<th>Variable name</th>
<th>Value (on my machine)</th>
<th>Purpose?</th>
</tr>
<tr>
<td>$0</td>
<td>&#8220;irb&#8221;</td>
<td>Name of current script executing</td>
</tr>
<tr>
<td>$&#8221;</td>
<td>[&#8221;e2mmap.rb&#8221;, &#8220;irb/init.rb&#8221;, &#8220;irb/workspace.rb&#8221;, &#8220;irb/context.rb&#8221;, &#8220;irb/extend-command.rb&#8221;, &#8220;irb/output-method.rb&#8221;, &#8220;irb/notifier.rb&#8221;, &#8220;irb/slex.rb&#8221;, &#8220;irb/ruby-token.rb&#8221;, &#8220;irb/ruby-lex.rb&#8221;, &#8220;readline.bundle&#8221;, &#8220;irb/input-method.rb&#8221;, &#8220;irb/locale.rb&#8221;, &#8220;irb.rb&#8221;]</td>
<td>Alias for $LOADED_FEATURES</td>
</tr>
<tr>
<td>$$</td>
<td>6100</td>
<td>Ruby interpreter process ID</td>
</tr>
<tr>
<td>$&lt;</td>
<td>ARGF</td>
<td>Points to ARGF (user input)</td>
</tr>
<tr>
<td>$_</td>
<td>nil</td>
<td>Last string read by &#8216;gets&#8217;</td>
</tr>
<tr>
<td>$-K</td>
<td>&#8220;NONE&#8221;</td>
<td>$KCODE option passed via command line</td>
</tr>
<tr>
<td>$DEBUG</td>
<td>false</td>
<td>Can be set to true with ruby &#8211;debug myscript.rb. Just for program use I think?</td>
</tr>
<tr>
<td>$-i</td>
<td>nil</td>
<td>See ruby command line options: in-place-edit mode</td>
</tr>
<tr>
<td>$deferr</td>
<td>#</td>
<td>Usually points to $stderr</td>
</tr>
<tr>
<td>$/</td>
<td>&#8220;\n&#8221;</td>
<td>Input record separator</td>
</tr>
<tr>
<td>$&#8217;</td>
<td>nil</td>
<td>Text after regexp match</td>
</tr>
<tr>
<td>$stdout</td>
<td>#</td>
<td>Standard output (eg, the console usually)</td>
</tr>
<tr>
<td>$-l</td>
<td>false</td>
<td>See ruby command line options: automatic line-ending processing</td>
</tr>
<tr>
<td>$LOAD_PATH</td>
<td>[&#8221;/usr/local/lib/ruby/site_ruby/1.8&#8243;, &#8220;/usr/local/lib/ruby/site_ruby/1.8/i686-darwin9.0.0&#8243;, &#8220;/usr/local/lib/ruby/site_ruby&#8221;, &#8220;/usr/local/lib/ruby/1.8&#8243;, &#8220;/usr/local/lib/ruby/1.8/i686-darwin9.0.0&#8243;, &#8220;.&#8221;]</td>
<td></td>
</tr>
<tr>
<td>$.</td>
<td>184</td>
<td>Last line of script read by interpreter</td>
</tr>
<tr>
<td>$KCODE</td>
<td>&#8220;NONE&#8221;</td>
<td><em>Kanji</em>CODE - determines how Ruby handles characters</td>
</tr>
<tr>
<td>$-w</td>
<td>false</td>
<td>See Ruby intepreter command line options - sets $VERBOSE to true</td>
</tr>
<tr>
<td>$FILENAME</td>
<td>&#8220;-&#8221;</td>
<td>?</td>
</tr>
<tr>
<td>$defout</td>
<td>#</td>
<td>Usually points to $stdout</td>
</tr>
<tr>
<td>$,</td>
<td>nil</td>
<td>?</td>
</tr>
<tr>
<td>$`</td>
<td>nil</td>
<td>Text before regexp match</td>
</tr>
<tr>
<td>$*</td>
<td>[]</td>
<td>Command line arguments passed to current script</td>
</tr>
<tr>
<td>$stdin</td>
<td>#</td>
<td>Standard user input (usually, console)</td>
</tr>
<tr>
<td>$-F</td>
<td>nil</td>
<td>Field separator passed via command line</td>
</tr>
<tr>
<td>$-p</td>
<td>false</td>
<td>Used for command line file processing/looping (See also: -n)</td>
</tr>
<tr>
<td>$-I</td>
<td>[&#8221;/usr/local/lib/ruby/site_ruby/1.8&#8243;, &#8220;/usr/local/lib/ruby/site_ruby/1.8/i686-darwin9.0.0&#8243;, &#8220;/usr/local/lib/ruby/site_ruby&#8221;, &#8220;/usr/local/lib/ruby/1.8&#8243;, &#8220;/usr/local/lib/ruby/1.8/i686-darwin9.0.0&#8243;, &#8220;.&#8221;]</td>
<td>Library script path (passed via command line option -I)</td>
</tr>
<tr>
<td>$\</td>
<td>nil</td>
<td>Output record separator</td>
</tr>
<tr>
<td>$=</td>
<td>false</td>
<td>Was last regular expression match case-sensitive?</td>
</tr>
<tr>
<td>$binding</td>
<td>nil</td>
<td>?</td>
</tr>
<tr>
<td>$-v</td>
<td>false</td>
<td>Alias for &#8211;verbose command line option</td>
</tr>
<tr>
<td>$&gt;</td>
<td>#</td>
<td>Points to standard output</td>
</tr>
<tr>
<td>$&amp;</td>
<td>nil</td>
<td>Last matched regular expression (also $1, $2, etc)</td>
</tr>
<tr>
<td>$!</td>
<td>nil</td>
<td>Last raised exception</td>
</tr>
<tr>
<td>$PROGRAM_NAME</td>
<td>&#8220;irb&#8221;</td>
<td>Alias for $0</td>
</tr>
<tr>
<td>$LOADED_FEATURES</td>
<td>[&#8221;e2mmap.rb&#8221;, &#8220;irb/init.rb&#8221;, &#8220;irb/workspace.rb&#8221;, &#8220;irb/context.rb&#8221;, &#8220;irb/extend-command.rb&#8221;, &#8220;irb/output-method.rb&#8221;, &#8220;irb/notifier.rb&#8221;, &#8220;irb/slex.rb&#8221;, &#8220;irb/ruby-token.rb&#8221;, &#8220;irb/ruby-lex.rb&#8221;, &#8220;readline.bundle&#8221;, &#8220;irb/input-method.rb&#8221;, &#8220;irb/locale.rb&#8221;, &#8220;irb.rb&#8221;]</td>
<td>Alias for $&#8221;</td>
</tr>
<tr>
<td>$?</td>
<td>nil</td>
<td>Status of last executed child process (useful with Kernel#system and similar)</td>
</tr>
<tr>
<td>$;</td>
<td>nil</td>
<td>Input field separator</td>
</tr>
<tr>
<td>$SAFE</td>
<td>0</td>
<td>Ruby safe mode</td>
</tr>
<tr>
<td>$-d</td>
<td>false</td>
<td>Command line option &#8211;debug</td>
</tr>
<tr>
<td>$:</td>
<td>[&#8221;/usr/local/lib/ruby/site_ruby/1.8&#8243;, &#8220;/usr/local/lib/ruby/site_ruby/1.8/i686-darwin9.0.0&#8243;, &#8220;/usr/local/lib/ruby/site_ruby&#8221;, &#8220;/usr/local/lib/ruby/1.8&#8243;, &#8220;/usr/local/lib/ruby/1.8/i686-darwin9.0.0&#8243;, &#8220;.&#8221;]</td>
<td>Alias for library path(?)</td>
</tr>
<tr>
<td>$-0</td>
<td>&#8220;\n&#8221;</td>
<td>Separator character(?)</td>
</tr>
<tr>
<td>$+</td>
<td>nil</td>
<td>?</td>
</tr>
<tr>
<td>$-a</td>
<td>false</td>
<td>Ruby command line options: auto-split mode</td>
</tr>
<tr>
<td>$VERBOSE</td>
<td>false</td>
<td>Ruby command line options: &#8211;verbose (some methods print extra information if this is on)</td>
</tr>
<tr>
<td>$stderr</td>
<td>#</td>
<td>Standard error destination</td>
</tr>
<tr>
<td>$~</td>
<td>nil</td>
<td>Last matched regular expression data (instance of MatchData)</td>
</tr>
<tr>
<td>$@</td>
<td>nil</td>
<td>Position of an error occurence</td>
</tr>
</tbody>
</table>
<p>
<b>References</b></p>
<p>
<a href="http://www.ruby-doc.org/docs/UsersGuide/rg/globalvars.html">http://www.ruby-doc.org/docs/UsersGuide/rg/globalvars.html</a><br/><br />
<a href="http://phrogz.net/programmingruby/rubyworld.html">http://cbcg.net/talks/rubyidioms/index.html</a><br/><br />
<a href="http://www.math.hokudai.ac.jp/~gotoken/ruby/ruby-uguide/uguide20.html">http://www.math.hokudai.ac.jp/~gotoken/ruby/ruby-uguide/uguide20.html</a><br/><br />
Hal Fulton: The Ruby Way (2nd Edition), Addison Wesley</p>
 <img src="http://blog.trapdoor1.net/wp-content/plugins/feed-statistics.php?view=1&post_id=31" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.trapdoor1.net/2008/05/04/under-the-hood-rubys-global-variables/feed/</wfw:commentRss>
		</item>
		<item>
		<title>AJAX performance trickery</title>
		<link>http://blog.trapdoor1.net/2008/05/03/ajax-performance-trickery/</link>
		<comments>http://blog.trapdoor1.net/2008/05/03/ajax-performance-trickery/#comments</comments>
		<pubDate>Sat, 03 May 2008 22:28:09 +0000</pubDate>
		<dc:creator>robin</dc:creator>
		
		<category><![CDATA[AJAX]]></category>

		<category><![CDATA[yslow]]></category>

		<guid isPermaLink="false">http://blog.trapdoor1.net/?p=29</guid>
		<description><![CDATA[This is a comprehensive guide to improving AJAX performance, including a guide to a Firefox plugin I hadn&#8217;t come across before - YSlow.
To me, AJAX performance isn&#8217;t so much a scalability issue, as a user interface one. The slicker and more responsive the interface, the better the user experience. And so a deeper understanding of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ibm.com/developerworks/web/library/wa-aj-perform/?ca=dgr-lnxw01FasterAjax">This</a> is a comprehensive guide to improving AJAX performance, including a guide to a Firefox plugin I hadn&#8217;t come across before - <a href="http://developer.yahoo.com/yslow/">YSlow</a>.</p>
<p>To me, AJAX performance isn&#8217;t so much a scalability issue, as a user interface one. The slicker and more responsive the interface, the better the user experience. And so a deeper understanding of the AJAX protocol has got to be a good thing.</p>
<p><a href="http://www.ibm.com/developerworks/web/library/wa-aj-perform/?ca=dgr-lnxw01FasterAjax">http://www.ibm.com/developerworks/web/library/wa-aj-perform/?ca=dgr-lnxw01FasterAjax</a></p>
 <img src="http://blog.trapdoor1.net/wp-content/plugins/feed-statistics.php?view=1&post_id=29" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.trapdoor1.net/2008/05/03/ajax-performance-trickery/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Optimizing ActiveRecord :includes with :select</title>
		<link>http://blog.trapdoor1.net/2008/04/24/optimizing-activerecord-includes-with-select/</link>
		<comments>http://blog.trapdoor1.net/2008/04/24/optimizing-activerecord-includes-with-select/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 17:51:52 +0000</pubDate>
		<dc:creator>robin</dc:creator>
		
		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[activerecord]]></category>

		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.trapdoor1.net/?p=28</guid>
		<description><![CDATA[I have just read two posts (here and here), both of them discussing the sometimes formidable challenges faced when attempting to optimize ActiveRecord&#8217;s performance.
For me, ActiveRecord is easily Rails&#8217; weakest link. Arguably, part of the problem is its ease of use. The object-oriented syntax means many developers find it far too easy to avoid opening [...]]]></description>
			<content:encoded><![CDATA[<p>I have just read two posts (<a href="http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/">here</a> and <a href="http://work.rowanhick.com/2008/02/12/how-to-avoid-hanging-yourself-with-rails/">here</a>), both of them discussing the sometimes formidable challenges faced when attempting to optimize ActiveRecord&#8217;s performance.</p>
<p>For me, ActiveRecord is easily Rails&#8217; weakest link. Arguably, part of the problem is its ease of use. The object-oriented syntax means many developers find it far too easy to avoid opening up the hood and get their hands dirty with raw SQL, something which - in my opinion - every web developer should be able to do. But this is hardly AR&#8217;s fault. If that was the only problem, then ActiveRecord could stroll away unscathed while the workmen stood around blaming their tools. The real problems lie in other areas, and for me the most common I encounter is its inability to join two tables without then selecting every column in each table in the query.</p>
<p>For example:</p>
<pre name="code" class="ruby">
User.find :all, :include =&gt; [ :posts, :comments ], :select =&gt; 'users.id, users.name, comments.content, posts.title'
</pre>
<p>will ignore the <code>:include</code> entirely, and go ahead and try to select from tables which weren&#8217;t included in the query. (This seems to have changed from earlier versions of AR, which ignored the <code>:select</code> options instead). Either way, this behaviour means it is difficult or impossible to sculpt elegant, effecient queries in many cases, and seriously erodes AR&#8217;s performance on complex queries.</p>
<p>I&#8217;ve seen a few patches published to solve this problem - and the highly useful <a href="http://assertbuggy.blogspot.com/2007/05/activerecord-select-with-include.html">select_with_include</a> gem packaged up one of these patches, but sadly seems to be broken with the more recent builds of ActiveRecord (probably since <a href="http://dev.rubyonrails.org/changeset/8672">this change</a>, which I&#8217;m not sure fixes the same problem). Finding an alternative is high on my list of priorities, but surely something should have been baked into AR itself by now?</p>
 <img src="http://blog.trapdoor1.net/wp-content/plugins/feed-statistics.php?view=1&post_id=28" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.trapdoor1.net/2008/04/24/optimizing-activerecord-includes-with-select/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Storing Rails&#8217; Flash object throughout multiple redirects</title>
		<link>http://blog.trapdoor1.net/2008/04/24/storing-rails-flash-object-throughout-multiple-redirects/</link>
		<comments>http://blog.trapdoor1.net/2008/04/24/storing-rails-flash-object-throughout-multiple-redirects/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 10:36:09 +0000</pubDate>
		<dc:creator>robin</dc:creator>
		
		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://blog.trapdoor1.net/?p=26</guid>
		<description><![CDATA[I am occasionally faced with the sometimes awkward problem of how to store a Flash message during more than one redirect. The problem is that the flash is usually cleared after one redirect, but sometimes you want to redirect more than once, but retain some flash message to display on the final destination.
These less than [...]]]></description>
			<content:encoded><![CDATA[<p>I am occasionally faced with the sometimes awkward problem of how to store a Flash message during more than one redirect. The problem is that the flash is usually cleared after one redirect, but sometimes you want to redirect more than once, but retain some flash message to display on the final destination.</p>
<p>These less than well known Rails methods probably hold the answer.<br />
<a href="http://api.rubyonrails.com/classes/ActionController/Flash/FlashHash.html"> http://api.rubyonrails.com/classes/ActionController/Flash/FlashHash.html</a></p>
 <img src="http://blog.trapdoor1.net/wp-content/plugins/feed-statistics.php?view=1&post_id=26" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.trapdoor1.net/2008/04/24/storing-rails-flash-object-throughout-multiple-redirects/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Calling SetReturnURL from ebay4r</title>
		<link>http://blog.trapdoor1.net/2008/04/15/calling-setreturnurl-from-ebay4r/</link>
		<comments>http://blog.trapdoor1.net/2008/04/15/calling-setreturnurl-from-ebay4r/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 11:42:22 +0000</pubDate>
		<dc:creator>robin</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[ebay]]></category>

		<category><![CDATA[ebay4r]]></category>

		<category><![CDATA[setreturnurl]]></category>

		<category><![CDATA[SOAP]]></category>

		<guid isPermaLink="false">http://blog.trapdoor1.net/?p=25</guid>
		<description><![CDATA[Garry Dolley&#8217;s ebay4r gem provides a Ruby interface to eBay&#8217;s SOAP API.
The following script extends it to allow the calling of eBay&#8217;s SetReturnURL method - required on a one-off basis to define redirect URLs for any eBay application authenticating users over the web.
ebay4r attempts to authenticate itself using the standard authToken, but this is one [...]]]></description>
			<content:encoded><![CDATA[<p>Garry Dolley&#8217;s <a href="http://scie.nti.st/2006/12/15/ebay4r">ebay4r</a> gem provides a Ruby interface to eBay&#8217;s SOAP API.</p>
<p>The following script extends it to allow the calling of eBay&#8217;s <a href="http://developer.ebay.com/DevZone/XML/docs/Reference/eBay/SetReturnURL.html">SetReturnURL</a> method - required on a one-off basis to define redirect URLs for any eBay application authenticating users over the web.</p>
<p>ebay4r attempts to authenticate itself using the standard authToken, but this is one of the few calls which requires a username and password to be supplied instead of the token. The following script fixes the problem by inserting the required data into the header of the SOAP request before sending.</p>
<p>If there is a more straightforward way of doing this, I&#8217;d like to know - extensive delving into the ebay4r docs and examples revealed nothing.</p>
<pre name="code" class="ruby">
require 'rubygems'
require 'ebayapi'

# your API details
appId = 'RobinWat-xxxx-xxxx-a9a5-b2a1e596xxxx'
devId = 'a696b358-xxxx-xxxx-b2e0-100b3fa8xxxx'
certId = '0c2d9022-xxxx-xxxx-9684-9082e9a2xxxx'
authToken = ''     # not needed for this call

# I had to use a sandbox test user here
username = 'testuser_xxx1'
password = 'xxxxxx'

accepturl = 'https://www.example.com/accept'
rejecturl = 'https://www.example.com/reject'
runame = 'developer-appname-auth'
action = 'Add'       # or 'Update'
application = 'yourappname'					

########################

ebay = EBay::API.new(authToken, devId, appId, certId, :sandbox => true)
ebay.debug = true

class EBay::RequesterCredentialsHandler
&nbsp;&nbsp;Username = XSD::QName.new(nil, 'n1:Username')
&nbsp;&nbsp;Password = XSD::QName.new(nil, 'n1:Password')

&nbsp;&nbsp;def on_simple_outbound
&nbsp;&nbsp;&nbsp;&nbsp;{ EbayAuthToken => @token,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Credentials => { DevId => @devId, AppId => @appId, AuthCert => @cert, Username => @username, Password => @password } }
&nbsp;&nbsp;end
end

ebay.instance_eval do
&nbsp;&nbsp;@header_handler.instance_eval { @username, @password = username, password }
end

ebay.SetReturnURL(
&nbsp;&nbsp;:AuthenticationEntry => EBay.AuthenticationEntry({
&nbsp;&nbsp;&nbsp;&nbsp;:AcceptURL => accepturl,
&nbsp;&nbsp;&nbsp;&nbsp;:RejectURL => rejecturl,
&nbsp;&nbsp;&nbsp;&nbsp;:PrivacyPolicyURL => nil,
&nbsp;&nbsp;&nbsp;&nbsp;:RuName => runame,
&nbsp;&nbsp;&nbsp;&nbsp;:TokenReturnMethod => 'FetchToken'}),
&nbsp;&nbsp;:Action => action,
&nbsp;&nbsp;:ApplicationDisplayName => application
)
</pre>
 <img src="http://blog.trapdoor1.net/wp-content/plugins/feed-statistics.php?view=1&post_id=25" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.trapdoor1.net/2008/04/15/calling-setreturnurl-from-ebay4r/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Modal dialog windows for JavaScript</title>
		<link>http://blog.trapdoor1.net/2008/04/14/modal-dialog-windows-for-javascript/</link>
		<comments>http://blog.trapdoor1.net/2008/04/14/modal-dialog-windows-for-javascript/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 08:42:25 +0000</pubDate>
		<dc:creator>robin</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[ibox]]></category>

		<category><![CDATA[thickbox]]></category>

		<guid isPermaLink="false">http://blog.trapdoor1.net/?p=24</guid>
		<description><![CDATA[Carefully implemented, modal dialog windows can dramatically improve a user interface. There are a number of libraries which offer such a system, but many have fundamental differences in design, or require certain external JS libraries, and finding the right one for me has proven a bit challenging.
My requirements: compatibility with JQuery, and importantly, the ability [...]]]></description>
			<content:encoded><![CDATA[<p>Carefully implemented, modal dialog windows can dramatically improve a user interface. There are a number of libraries which offer such a system, but many have fundamental differences in design, or require certain external JS libraries, and finding the right one for me has proven a bit challenging.</p>
<p>My requirements: compatibility with JQuery, and importantly, the ability to degrade gracefully for those users who disable javascript. Unfortunately, this last point is where <a href="http://jquery.com/demo/thickbox/">Thickbox</a>, otherwise the leading candidate for JQuery, falls down.</p>
<p>The solution could well be iBox. Independent of all external javascript libraries, it is nevertheless lightweight (7kb compressed), works first time out of the box - no pun intended - and since it doesn&#8217;t hijack the HREF tag, it degrades as nicely as you could wish for.</p>
<p><a href="http://www.ibegin.com/labs/ibox/">http://www.ibegin.com/labs/ibox/</a></p>
 <img src="http://blog.trapdoor1.net/wp-content/plugins/feed-statistics.php?view=1&post_id=24" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.trapdoor1.net/2008/04/14/modal-dialog-windows-for-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Extending restful_authentication</title>
		<link>http://blog.trapdoor1.net/2008/04/09/restful-authentication-for-extended-role-based-user-checking/</link>
		<comments>http://blog.trapdoor1.net/2008/04/09/restful-authentication-for-extended-role-based-user-checking/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 18:34:14 +0000</pubDate>
		<dc:creator>robin</dc:creator>
		
		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[acts_as_authenticated]]></category>

		<category><![CDATA[restful_authentication]]></category>

		<guid isPermaLink="false">http://blog.trapdoor1.net/?p=21</guid>
		<description><![CDATA[Most websites need to offer users several levels of access. Sometimes it&#8217;s as simple as a straight choice between logged in, or logged out - something which both restful_authentication and acts_as_authenticated handle competently.
As a site grows, however, so does the likelihood that further levels of authentication will need to be checked. Now, there&#8217;s an entire [...]]]></description>
			<content:encoded><![CDATA[<p>Most websites need to offer users several levels of access. Sometimes it&#8217;s as simple as a straight choice between logged in, or logged out - something which both <a href="http://weblog.techno-weenie.net/2006/8/1/restful-authentication-plugin">restful_authentication</a> and <a href="http://technoweenie.stikipad.com/plugins/show/Acts+as+Authenticated">acts_as_authenticated</a> handle competently.</p>
<p>As a site grows, however, so does the likelihood that further levels of authentication will need to be checked. Now, there&#8217;s an entire industry dedicated to solving this problem - but here&#8217;s a simple and logical way of utilizing some of restful_authentication&#8217;s methods to implement such a system. I haven&#8217;t tested this in acts_as_authenticated - but as far as I know it should work fine there too.</p>
<p>Firstly, we need to duplicate restful_authentication&#8217;s <code>login_required</code> method, in order to handle a new level of user. As an example, we&#8217;ll write a method <code>contributor_required</code>, which will act as a filter to ensure a given set of actions are only available to one of a website&#8217;s contributors. (I am assuming the existence of a method or two, but these should be pretty self-explanatory.)</p>
<pre name="code" class="ruby">
class ApplicationController &lt; ActionController::Base
&nbsp;&nbsp;include AuthenticatedSystem
&nbsp;&nbsp;...

&nbsp;&nbsp;protected

&nbsp;&nbsp;def contributor_required
&nbsp;&nbsp;&nbsp;&nbsp;login_required

&nbsp;&nbsp;&nbsp;&nbsp;if not current_user.is_contributor?
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;store_location
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash[:notice] = "You must be a contributor to enter here!"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirect_to new_user_contributor_path(current_user)   # or, send wherever your app requires
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true
&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;end
end</pre>
<p>There are a couple of important things to note here. The first line of the method calls restful_authentication&#8217;s own <code>login_required</code> method. This could almost be viewed as a &#8217;super&#8217; method: we are assuming that in order to be a contributor, you must already be registered user - and if you&#8217;re not, you will be redirected to the basic login/register pages at this point.</p>
<p>Any deeper levels of user we want to create later - senior_contributor, perhaps - should therefore call <code>contributor_required</code> in place of <code>login_required</code>. This method will then itself &#8216;work up the chain&#8217; and eventually end up calling <code>login_required</code>. We could construct an arbitrarily-sized &#8216;tree&#8217; of authentication in this manner - mirroring many real-life authentication needs.</p>
<p>One further plus point is that the check for <code>login_required</code> ensures we can rely on the validity of <code>current_user</code> a little later on.</p>
<p>The other thing to notice is that - if the assumed <code>is_contributor?</code> method returns false - we call restful_authentication&#8217;s <code>store_location</code> method. This is a simple method which stores the requested URI in the session, allowing access to it later. It means we should be able to redirect back to the requested page, if we can approve the user&#8217;s contributor status.</p>
<p>So, all that is left is to utilize the code in our controller, where  <code>contributor_required</code> can be used alongside <code>login_required</code>. Also, the use of the usual <code>redirect_back_or_default</code> method means we should be redirected back here after we&#8217;ve registered the user as a contributor, or whatever we need to do.</p>
<pre name="code" class="ruby">
class ContributionsController
&nbsp;&nbsp;before_filter :login_required, :only =&gt; [ :index, :show ]
&nbsp;&nbsp;before_filter :contributor_required, :only =&gt; [ :new, :create, :edit, :update, :destroy ]

&nbsp;&nbsp;...

&nbsp;&nbsp;def create
&nbsp;&nbsp;&nbsp;&nbsp;...
&nbsp;&nbsp;&nbsp;&nbsp;respond_to do |format|
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.html { redirect_back_or_default( contributions_path(@contribution) ) }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...
&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;end
end</pre>
<p>And voila! Simple, but potentially powerful role-based authentication for Rails.</p>
 <img src="http://blog.trapdoor1.net/wp-content/plugins/feed-statistics.php?view=1&post_id=21" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.trapdoor1.net/2008/04/09/restful-authentication-for-extended-role-based-user-checking/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Haml scaffolding for Rails</title>
		<link>http://blog.trapdoor1.net/2008/04/09/haml-scaffolding-for-rails/</link>
		<comments>http://blog.trapdoor1.net/2008/04/09/haml-scaffolding-for-rails/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 13:10:17 +0000</pubDate>
		<dc:creator>robin</dc:creator>
		
		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[haml]]></category>

		<guid isPermaLink="false">http://blog.trapdoor1.net/?p=19</guid>
		<description><![CDATA[Haml is a masterstroke - since moving over to it, writing markup has ceased being the chore it was. In fact, it&#8217;s so logical and intuitive, and saves so much time, I often wonder how I coped without for so long.
The one irritation is that Rails does not yet support Haml in its scaffold generator, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://haml.hamptoncatlin.com/">Haml</a> is a masterstroke - since moving over to it, writing markup has ceased being the chore it was. In fact, it&#8217;s so logical and intuitive, and saves so much time, I often wonder how I coped without for so long.</p>
<p>The one irritation is that Rails does not yet support Haml in its scaffold generator, and new views and layouts have to be manually converted each time.</p>
<p>I have found two solutions to this, so far: firstly, <a href="http://blog.citrusbyte.com/2008/3/11/what-s-that-rspec-haml-scaffolds-yes-it-is">Daniel Fischer&#8217;s haml generator</a> kills two birds with one stone, by also including support for generating relevant RSpec testing configuration files. A brief testing has revealed no obvious problems.</p>
<p>Secondly, James Golick&#8217;s <a href="http://jamesgolick.com/resource_controller">resource_controller</a> claims to do a similar job, although I am yet to test this at the time of writing.</p>
<p>Next on my wishlist: An automatic ERB &lt;-&gt; Haml converter.</p>
 <img src="http://blog.trapdoor1.net/wp-content/plugins/feed-statistics.php?view=1&post_id=19" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.trapdoor1.net/2008/04/09/haml-scaffolding-for-rails/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Object.too_clever_by_half? rescue nil</title>
		<link>http://blog.trapdoor1.net/2008/04/05/object-too_clever_by_half-rescue-nil/</link>
		<comments>http://blog.trapdoor1.net/2008/04/05/object-too_clever_by_half-rescue-nil/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 13:08:21 +0000</pubDate>
		<dc:creator>robin</dc:creator>
		
		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.trapdoor1.net/?p=15</guid>
		<description><![CDATA[Monkey-patching proposals have abounded in the Ruby community recently - including, but not limited to Object#andand, Object#_? and SafeNil and Object#method_.
The underlying aim of all seems to be to keep code as DRY as possible. Inline validity checking is considered too ugly and verbose, as in the following snippet:
@person.name unless @person.nil?
Most of the proposals, however, [...]]]></description>
			<content:encoded><![CDATA[<p>Monkey-patching proposals have abounded in the Ruby community recently - including, but not limited to <a title="http://weblog.raganwald.com/2008/01/objectandand-objectme-in-ruby.html" href="http://weblog.raganwald.com/2008/01/objectandand-objectme-in-ruby.html">Object#andand</a>, <a href="http://hobocentral.net/blog/2007/08/25/quiz/">Object#_? and SafeNil</a> and <a href="http://www.urubatan.info/2008/03/a-better-try-for-ruby-why-not-do-the-groovy-way/">Object#method_</a>.</p>
<p>The underlying aim of all seems to be to keep code as <abbr title="Don't Repeat Yourself">DRY</abbr> as possible. Inline validity checking is considered too ugly and verbose, as in the following snippet:</p>
<p><code>@person.name unless @person.nil?</code></p>
<p>Most of the proposals, however, make no mention of Ruby&#8217;s <a href="http://www.rubycentral.com/pickaxe/tut_exceptions.html">exception handling</a> routines. These routines are designed for the very purpose of removing unpleasant and repetitive error-handling procedures from code, and could be readily utilized in most or all the examples I have seen.</p>
<p>Ruby&#8217;s dynamic language features are powerful and alluring: but I believe that altering the fundamental behaviour of <code>NilClass</code>, as some have suggested, should be avoided wherever possible - and that probably means always.</p>
<p>Or to put it another way: When does <abbr title="Don't repeat yourself">DRY</abbr> become more important than <abbr title="Keep it simple, stupid">KISS</abbr>?</p>
 <img src="http://blog.trapdoor1.net/wp-content/plugins/feed-statistics.php?view=1&post_id=15" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.trapdoor1.net/2008/04/05/object-too_clever_by_half-rescue-nil/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Shifting paradigms</title>
		<link>http://blog.trapdoor1.net/2008/04/03/shifting-paradigms/</link>
		<comments>http://blog.trapdoor1.net/2008/04/03/shifting-paradigms/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 22:12:11 +0000</pubDate>
		<dc:creator>robin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[zen]]></category>

		<guid isPermaLink="false">http://blog.trapdoor1.net/?p=13</guid>
		<description><![CDATA[Anand Rajaraman describes a group of students eschewing complicated movie data-mining algorithms in favour of a simple, effective alternative tactic: comparing their data with additional information from the IMDB website.
In the same post, he compares this with Google&#8217;s great leap forward in the late nineties: the inclusion of hyperlink counts and anchor text recognition in [...]]]></description>
			<content:encoded><![CDATA[<p>Anand Rajaraman <a title="describes" href="http://anand.typepad.com/datawocky/2008/03/more-data-usual.html">describes</a> a group of students eschewing complicated movie data-mining algorithms in favour of a simple, effective alternative tactic: comparing their data with additional information from the <abbr title="Internet Movie Database">IMDB</abbr> website.</p>
<p>In the same post, he compares this with Google&#8217;s great leap forward in the late nineties: the inclusion of hyperlink counts and anchor text recognition in their search engine results, which helped put them firmly one step ahead of the competition.</p>
<p>He sums it up thus:</p>
<blockquote><p>&#8230; if you have limited resources, add more data rather than fine-tuning the weights on your fancy machine-learning algorithm. </p></blockquote>
<p>I would go a step further. Both of these are perfect examples of how the biggest leaps forward usually come from a paradigm shift, a fundamental change in thinking - a change which is often profoundly simpler than the alternatives, but paradoxically, much harder to see.</p>
 <img src="http://blog.trapdoor1.net/wp-content/plugins/feed-statistics.php?view=1&post_id=13" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.trapdoor1.net/2008/04/03/shifting-paradigms/feed/</wfw:commentRss>
		</item>
		<item>
		<title>On the problem of configuring a server.</title>
		<link>http://blog.trapdoor1.net/2008/04/03/on-the-problem-of-configuring-a-server/</link>
		<comments>http://blog.trapdoor1.net/2008/04/03/on-the-problem-of-configuring-a-server/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 17:57:17 +0000</pubDate>
		<dc:creator>robin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[apache]]></category>

		<category><![CDATA[server]]></category>

		<category><![CDATA[slicehost]]></category>

		<guid isPermaLink="false">http://trapdoor1.wordpress.com/?p=8</guid>
		<description><![CDATA[Building a server from scratch is hardly trivial, and I&#8217;m far from an expert in the finer points of the art. And since the implications of getting it wrong don&#8217;t bear considering for too long, getting the right information is crucial. Enter Slicehost&#8217;s series of in-depth tutorials.
I heartily applaud the philosophy of gentle guidance which [...]]]></description>
			<content:encoded><![CDATA[<p>Building a server from scratch is hardly trivial, and I&#8217;m far from an expert in the finer points of the art. And since the implications of getting it wrong don&#8217;t bear considering for too long, getting the right information is crucial. Enter Slicehost&#8217;s <a href="http://articles.slicehost.com/" title="series of in-depth tutorials">series of in-depth tutorials</a>.</p>
<p>I heartily applaud the philosophy of gentle guidance which deliberately stops short of trying to define a one-size-fits-all configuration for every circumstance. It is left to the reader to weigh up the possible options and make his own decision - but the information presented is first-class, with a strong emphasis on security which sometimes seems to be lacking in many other articles.</p>
<p>As if that wasn&#8217;t enough, there are even multiple versions of each tutorial, tailored to different Linux distributions.</p>
 <img src="http://blog.trapdoor1.net/wp-content/plugins/feed-statistics.php?view=1&post_id=11" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.trapdoor1.net/2008/04/03/on-the-problem-of-configuring-a-server/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
