raganwald
(This is a snapshot of my old weblog. New posts and selected republished essays can be found at raganwald.com.)

Monday, December 10, 2007
  Utility Belt


Utility Belt is a grab-bag of tricks, tools, techniques, trifles, and toys for IRB, including convenience methods, language patches, and useful extensions. It also includes a couple command-line widgets. Its primary inspirations were an awesome gem called Wirble and a blog post by Amy Hoy called “Secrets Of The Rails Console Ninjas”.

INSTALL

sudo gem install utility_belt

FEATURES




Who can resist publicizing a grab-bag gem that just happens to contain some code you snarfed from someone else? Not me! It’s like one of those vanity books of poetry: your poem is included provided you buy twenty copies for your friends and family…

Labels:

 

Comments on “Utility Belt:
Wait, the code it contains is code you snarfed?

Wouldn't that be like buying a book because it contains a poem you plagiarized?

Also, utility_belt is cool. It's worth twice the price just for the python-like "_" variable.
 
Wait, the code it contains is code you snarfed?

Wouldn't that be like buying a book because it contains a poem you plagiarized?


If you're the type to snarf, you're the type to buy a book containing a poem you snarfed.

Snarfing isn't the same as plagiarizing (although I suspect you know that)" "To acquire, with little concern for legal forms or politesse (but not quite by stealing)." In this case, it was a direct port of a Javascript library written by Oliver Steele. He didn't seem to mind: he linked to it on his weblog.
 
It's so great, there has to be a catch! And there is, unfortunately.

It breaks rails quite significantly, by causing all 'edit' actions to be 'hidden', and thus not work.

How this happens is quite involved...

1) If you put 'require utility_belt' in your ~/.irbrc, then utility belt always gets loaded, even if you're not running irbrc

2) The file utility_belt/lib/interactive_editor.rb defines a method called 'edit' as an instance method under Object

3) class Class is inherited from Object, so this means that not only does every object have an instance method of 'edit', every class now has a class method of 'edit'

4) Rails marks all methods in ActionController::Base as hidden

5) This causes the 'edit' method to be marked as hidden.

Your .rhtml template file will get called without the 'edit' in the controller ever running, so in 99% of cases, you'll get an error indicating your @item is nil.

Sneaky eh?
The fix is to either not have utility belt in your .irbrc, or to edit the utility belt source to prevent it defining an 'edit' method on Object

Cheers!
 
Hey Orion - I know about that. I have a simple fix, which is renaming the edit method, and I'm going to deploy it soon. But what I want to do is hunt down the real problem and patch Rails. Because here's the thing - you said:

If you put 'require utility_belt' in your ~/.irbrc, then utility belt always gets loaded, even if you're not running irbrc

That is a bug in Rails, and a seriously weird one. It starts at ActiveSupport::Dependencies line 488, but where it goes from there I don't quite know.

Expect a release in the next few days renaming the edit method, but understand, this is a strictly a workaround to avoid a bug in Rails, and what I really want, and what the community really needs, is to find that bug and patch it.

Thanks Reg and Chalain for the props. :-)
 




<< Home
Reg Braithwaite


Recent Writing
Homoiconic Technical Writing / raganwald.posterous.com

Books
What I‘ve Learned From Failure / Kestrels, Quirky Birds, and Hopeless Egocentricity

Share
rewrite_rails / andand / unfold.rb / string_to_proc.rb / dsl_and_let.rb / comprehension.rb / lazy_lists.rb

Beauty
IS-STRICTLY-EQUIVALENT-TO-A / Spaghetti-Western Coding / Golf is a good program spoiled / Programming conventions as signals / Not all functions should be object methods

The Not So Big Software Design / Writing programs for people to read / Why Why Functional Programming Matters Matters / But Y would I want to do a thing like this?

Work
The single most important thing you must do to improve your programming career / The Naïve Approach to Hiring People / No Disrespect / Take control of your interview / Three tips for getting a job through a recruiter / My favourite interview question

Management
Exception Handling in Software Development / What if powerful languages and idioms only work for small teams? / Bricks / Which theory fits the evidence? / Still failing, still learning / What I’ve learned from failure

Notation
The unary ampersand in Ruby / (1..100).inject(&:+) / The challenge of teaching yourself a programming language / The significance of the meta-circular interpreter / Block-Structured Javascript / Haskell, Ruby and Infinity / Closures and Higher-Order Functions

Opinion
Why Apple is more expensive than Amazon / Why we are the biggest obstacles to our own growth / Is software the documentation of business process mistakes? / We have lost control of the apparatus / What I’ve Learned From Sales I, II, III

Whimsey
The Narcissism of Small Code Differences / Billy Martin’s Technique for Managing his Manager / Three stories about The Tao / Programming Language Stories / Why You Need a Degree to Work For BigCo

History
06/04 / 07/04 / 08/04 / 09/04 / 10/04 / 11/04 / 12/04 / 01/05 / 02/05 / 03/05 / 04/05 / 06/05 / 07/05 / 08/05 / 09/05 / 10/05 / 11/05 / 01/06 / 02/06 / 03/06 / 04/06 / 05/06 / 06/06 / 07/06 / 08/06 / 09/06 / 10/06 / 11/06 / 12/06 / 01/07 / 02/07 / 03/07 / 04/07 / 05/07 / 06/07 / 07/07 / 08/07 / 09/07 / 10/07 / 11/07 / 12/07 / 01/08 / 02/08 / 03/08 / 04/08 / 05/08 / 06/08 / 07/08 /