Archive for April, 2009

April 14

Why I don’t object to Array#sum

Posted by mtoledo
Filed under ruby | 7 Comments

Raganwald has written a very elaborate piece about his “objection to Array#sum“. Since I patircularly like Array#sum, I thought I might weight in on my own blog.
First, I think that his piece has 2 different objections:
1) Array shouldn’t return true for a “responds_to? :sum” call if it has contents that can’t be summed ( like [...]

April 9

On caching expensive case conditions

Posted by mtoledo
Filed under ruby | No Comments

Ruby has a pretty expressive and flexible case statement. It actually differs from most other language’s ’switch’ statements in that it auto-breaks on each condition instead of falling through.

// C

switch (x) {
case 1:
doSomething();
break;
case 2:
doSomethingElse();
break;
}

# ruby

case x
when 1: do_something
when 2: do_something_else
end

I do think not having to break was the right decision, but not everyone agrees and [...]

April 8

Using ‘map’ effectively on ruby Hashes

Posted by mtoledo
Filed under ruby | 2 Comments

Ruby is a very powerful language, and the methods available to manipulate its 2 main data structures, Array and Hash, are really good. Though, some of them are really obscure, and for some other manipulations you are on your own. This happens specially with the Hash class.
To me, this is probably because although both Array [...]

April 7

Getting syntax highlighter to work on wordpress’s homepage (on some themes)

Posted by mtoledo
Filed under javascript | No Comments

Today I was trying to setup this blog with Syntax Highlighter Plus. Curiously, the syntax highlighting wouldn’t work on the home page where multiple posts are displayed, only when you clicked on a single post.
I’m adding this here because I couldn’t find anything about it anywhere except people suggesting to check the theme’s header and [...]