Working with Ruby
Hi, I am Jan. This is my old Ruby blog. I still post about Ruby, but I now do it on idiosyncratic-ruby.com. You should also install Irbtools to improve your IRB.

Organise your code comments with rake notes:todo!

Lots of IDEs (e.g. Netbeans) and some editors (e.g. gedit with plugins) have a nice feature: They show comments, which start with something like TODO or FIXME. Those annotations are quickly written and they make it harder to forget some things you wanted to (or have to) do.

I have just discovered that Rails has this feature already built-in!

rake notes

Just browse to your rails directory and type one of the following rake tasks:

rake notes:todo rake notes:fixme rake notes:optimize

It will show a nice comprehensive list of the files and lines, which have TODO, FIXME, or OPTIMIZE annotations. Note, that they are case sensitive and have to be written at the beginning of a comment. The shortcut rake notes combines the three of them.
You can also use your own words, but the resulting syntax is not so cool anymore…:

rake notes:custom ANNOTATION=COOL

Do not forget, that your own annotations are also case sensitive.

Search for thoughts

You can abuse the last command, to search through your whole rails project comments. This is possible, because the pattern is inserted as a part of this regexp: /#\s*(find_me):?\s*(.*)$/. So it is possible to run

rake notes:custom ANNOTATION=.*find_me

It works, but probably, the output after the line number is not that speaking anymore… But you can work around that by adding brackets:

rake notes:custom ANNOTATION=\(.*find_me.*\)

You have to escape some of the characters you pass (e.g. the brackets). One last hint: to use spaces in the search pattern, you can do something like this: find\\sme

I also noticed a little (but unimportant) bug.. because of the easy regexp, which is used for getting only the comments, it sometimes gets false positives, when # is used for string interpolation.

Creative Commons License

Tony | May 15, 2010

I was looking for something like this. I had no idea it was already included. Thanks