Ruby's a gem
Well, prompted by the many of my friends researching or actively using Rails and Ruby, I thought I would start checking it out.
As with many nice book authors these days (eg. Matt Reilly, Dave Rolskey & Ken Williams), a version (first edition) of the Programming Ruby book is available for free online. There is a second addition for purchasing which apparently covers features and libraries of Ruby version 1.8. From my reading so far, it will be a snap to pick up for an experienced Perl OO hack like myself. Of course similarity can often lead to frustration, but all the major nicities are there (albeit always in an OO form). Many of the core concepts are similar, yet are made available in a way that will be far more comfortable to newcomers than is Perl. For instance, every object inherits a .to_s() method—much simpler than explaining the ins, outs & special cases of Perl's stringification rules. The OO nature goes right to the core of the Ruby (everything is an object). The descriptive OO concepts used are those of message passing from SmallTalk, which will also be familiar to Objective-C programmers. The "every call is a method" style will also be familiar to (very serious) JavaScript/ECMAScript programmers. The book authors also happily point out where Ruby adheres to true Object Oriented style where Java strays. In short, it seems to combine all the good bits of the languages I love to use and love to admire. When I have done more research I will deliver my verdict as to whether there is Ruby in my future or not. Everything is an object?: Literally everything is an object. There is no exception for strings or numbers (unlike some other OO languages), although you can use simple operators on objects (via operator overloading). For example, look at this example adapted from chapter two of the Ruby book
product1 = "Spam" product2 = product1 product1[1] = 'h' product1 is: "Sham" product2 is: "Sham"product1 and product2 are local variables that each contain a reference to the same String object (which was magically brought into being by the double-quoted inline string literal. A lot like perl objects really. The biggest thing that's NOT like perl is that data types don't automatically coerce based on context. So you can't, for instance, do something like 5 + "5" which really sucks for file handling etc. Code blocks: Gratifyingly, Ruby has a very clean implementation of code blocks/closures/anonymous subs (depending on your language speak). Once again, nothing that you can't do in Perl (and i'm not sure i like the do ... end syntax), but such a clean, genuine OO, implementation is an absoulte joy. Ranges: In Ruby, a range is not a list—it's, well, a Range. An object of type Range that is, and Ranges have some rather nice properties. Take the following code example adapted from this chapter of the Ruby book:
fileHandle.each do
print if /start/../end/
end
It does what it looks like it's meant to do—prints any line in the input file that falls in between a line matching the regex /start/ and the one matching /end/. Not even Perl is that cool :) And if it was, Perl would call it DWIM—Ruby calls it the principle of least surprise...Update: Of course Perl's flip flop operator can have the same effect - which should be no surprise to me ;)
01:48 PM, 23 Jan 2005 by Mark Aufflick Permalink | Comments (1) |
Archive
October 2008 September 2008 August 2008 July 2008 June 2008 May 2008 March 2008 February 2008 January 2008 December 2007 November 2007 October 2007 September 2007 August 2007 July 2007 June 2007 May 2007 April 2007 March 2007 February 2007 January 2007 December 2006 November 2006 October 2006 September 2006 August 2006 July 2006 June 2006 May 2006 April 2006 March 2006 February 2006 January 2006 December 2005 November 2005 October 2005 September 2005 August 2005 July 2005 June 2005 May 2005 April 2005 March 2005 February 2005 January 2005 December 2004 November 2004 October 2004 September 2004 August 2004 July 2004 June 2004 May 2004 April 2004 March 2004 February 2004 January 2004 December 2003 November 2003 October 2003 September 2003 August 2003 Notifications Request notifications
Recent Comments | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Request notifications