Ruby Impressions So Far

Well I have decided to try to learn Ruby and see what I can create with its web frameworks (something like Sinatra or even Rails). So I picked up a couple of books and started reading.

So far here are my (read; from a long time C# developer) Ruby take aways.
* Class inheritance is single (like C#) but you can include unlimited number of “modules” as you like
* All Classes are partial.
* Basic built in classes is small set; Fixnum, Bignum, String, Range, Array and Hash
* Several of the “methods” do different thing based on case, ie “%w” and “%W” string delimiter – eek
* The inclusive and exclusive range of “..” and “…” is well weird.
* True, False, “0” and “1” are all logically “true” and only nil is “false” – uhm wow; this seriously tweeks my head.
* An array can contain any type (or object) which means “Array” is like Dictionary
* .freeze will let you make a class that cannot be modified – but evidently you will be ostracised by the Ruby community for using it.
* Class “Attributes” are like Clas Properties.
* The distinction between “@variable” and “@@variable” is that the single is instance variable and double is class variable (persists, think const).
* Methods (code that is def … end) doesnt need a “return” it magically returns the last value in the method. This is very strange to me as I want to see the “return batman;” – syntactical sugar I realize.
* Mixin method inheritance call is seemingly backwards from constants in their order of location. Is this just to confuse people? Seems like it to me.
* Same as JS with the ‘==’ and ‘===’ comparison operator. I wish C# had this operation as succient as this. The “is” and comparision of typeOf works but isnt as clear.
* “Unless” conditional statement is interesting. Its like reverse of an “if”.
* Statement modifiers are nice, but I can see it being confusing as its the logic to perform the statement after the statement, but it does make for succient code.
* Case statements dont have “fall through”
* “while” and “until” are opposite. “while” loop is as long as the condition is true, and “until” is until the condition is false.
* “for” loop is like “for each” in C#, meaning you get a local variable in the loop scope for iteration through a variable collection.
* “rescue” is like “catch” in exception handling
* “ensure” is like “finally” in exception handling
* “raise” is like “throw” in exception handling
* Exceptions bubble up the stack if no “rescue” handler is found – exactly like C#
* For a class definition the “<" is the same as ":", ie "class MyError < RuntimeError" same as "class MyError : RuntimeError" * Class method "initialize" is same as "~" * Using the "File.Open ... end" block is like a using() statement, in that the File is closed on block exit. * Threading is much simplier in design in Ruby over .NET threading - much.

0