19 Sep 2008 shlomif   » (Master)

Impressions from Ruby

Ahoy mateys! Arrrrrrrrrr! Happy Talk Like a Pirate Day!. In the piratey spirit, I decided today to get my act together, and start working on a project I've intended to write. Since I've been learning the Ruby programming language lately, I decided to write it in it, to learn more about Ruby and to experiment with it. In this post I'd like to blog about some of the facts I discovered that surprised me in Ruby.

First of all, I discovered that Ruby regular expressions don't have Perl 5's "\G" and /g feature that can be used to incrementally parse a string using regular expressions. The closest thing I could find was using .sub! (with the empty string), which does an in-place subtitution of a regular expression

The second thing I discovered was that Ruby did not have ++ or -- operators - one has to use += 1 and -= 1. When Ruby tried to parse a line containing "++" it yelled at me with an obscure error, that caused me to need to incrementally comment-out code until I found out what the problem was.

Another fact that disappointed me was that the Ruby debugger (ruby -rdebug) does not seem to have conditional breakpoints (i.e: break at a certain line only if a condition is met).

Finally, when I tried to do .inject { BLOCK } ("inject" is Ruby's list reduce / fold method), without a starting element, I discovered that it used the first element as a starting point instead of 0 or nil or whatever. Doing .inject(0) { BLOCK } in my case fixed it. This fact is documented in the documentation.

Otherwise, Ruby seems likable and I've been feeling I'm productive in it. I've been using RSpec for writing my automated tests. It's a so-called "Behaviour Driven Development" library, which is the same as Test-driven development, but RSpec is still nice.

Syndicated 2008-09-19 19:45:48 from shlomif

Latest blog entries     Older blog entries

New Advogato Features

FOAF updates: Trust rankings are now exported, making the data available to other users and websites. An external FOAF URI has been added, allowing users to link to an additional FOAF file.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!