Archive for the 'Ruby' Category

Testing Named Routes in the Rails Console

Tuesday, January 8th, 2008

I finally found out how to do this, from the Rails Routing shortcut by David Black. In the Rails console, do this:

include ActionController::UrlWriter
default_url_options[:host] = ‘whatever’

Then you can call your named route methods directly from the console.

Basking in the Solr Glow

Wednesday, January 2nd, 2008

I am happy to report that AltLaw.org’s switch to Solr has worked very well. Solr is a RESTful search engine, built on Lucene. The setup was more complicated than just using a search library, but the rewards were worth it.
Before, I was using Ferret, which I still like. It’s a [...]

Parsing Complex Comparisons

Tuesday, October 16th, 2007

An interesting tidbit: can your programming language parse a < b < c? Perl can’t. Ruby can, but returns an error “undefined method `>’ for false:FalseClass.” Interestingly, Python accepts it, and even gives the correct result. Something clever must be going on in the parser to make that work.
Update October 17: Although Lisp can’t [...]

Why Doesn’t My Rails App Use memcached with cached_model?

Thursday, October 4th, 2007

Answer: you’re using the latest version of Rails (1.2.3), which slightly changes the syntax of its SQL statements. cached_model relies on a regular expression to match that SQL statement.
To fix: Dive into the source of the cached_model gem, find the file lib/cached_model.rb, and change the first line after def self.find_by_sql to this:

[...]

Rails Sucks, Long Live Rails

Friday, August 17th, 2007

Wowsers. I just spent two nail-biting, hair-pulling days getting Ruby on Rails running on a new dedicated server. What’s the deal here? I spent the first six hours trying to get Capistrano to work with darcs. Then I gave up on Capistrano.
I didn’t know anything about Mongrel, nginx, Lighttpd, or any [...]

Ruby vs. Lisp

Tuesday, July 31st, 2007

I’m certainly not the first to do this, but I felt like writing it. Comparing Ruby and Common Lisp:
Syntax: Advantage, Common Lisp. No contest here. Ruby’s syntax is ugly, with all those ends hanging around and the { |var| … } block syntax. The one thing Ruby has going for it [...]

The Virtues of Static Typing

Monday, July 23rd, 2007

When I first discovered dynamically-typed languages like Perl and Ruby, I was convinced of their superiority to statically-typed languages like C++. No longer did I have to waste hours typing redundant type declarations or adding casts just to make the compiler happy. Dynamic typing allowed me to work quickly and unencumbered in what [...]

The Weirdness of C++

Sunday, July 15th, 2007

I’ve been dredging up my C++ for a class recently, and I’m struck by just how weird it feels now that I spend most of my time with Ruby.
I was all proud of myself for remembering how to write a copy constructor. Then I ran into a situation like this:

MyClass a = [...]

Learning to Cook With Ruby

Sunday, June 17th, 2007

I don’t much like programming language tutorials. They’re useful for getting the general sense of what a language is all about, but they inevitably elide too many crucial details to teach you how to write a real program.
When I got interested in Ruby, I read the on-line version of Programming Ruby: The Pragmatic Programmer’s [...]

Defining Eval … In a Library

Wednesday, June 13th, 2007

I was at LispNYC last night listening to Anton van Straaten discuss his work on R6RS, the new Scheme standard. One surprising change from R5RS is that eval is defined in a library.
Eval, in a library? Holy scopes! The Common Lispers in the audience were aghast. Even the Schemers were a [...]