Monday, December 22, 2008

Block-tastic

I am in the process of reading "The Little Book of Ruby" by Huw Collingbourne. I have found some very cool tricks that you can do in ruby, such as:

def sample
return 1, "new" <- return multiple data types
end

This also lends itself to arrays with multiple data types. Such as:

a = [1,sample,"hello"] <- which is [1,[1,"new"],"hello"] as I just learned

The each loop is very nice, similar to the foreach loop in c#.
Instead of:

foreach(int x in intlist)
{
Console.Writeline(x);
}

it is:

intlist.each do
|x|
Puts(x)
end

Another cool thing is the alternate syntax for delimiting blocks ie.

Given the each list above, the following is acceptable:

intlist.each{
|x|
Puts(x)
}

but remember to include either do or { on the same line as the each method, or (as i found out) it will throw an error.

Very cool stuff.
More observations to follow... Enjoy!

Getting my hands wet

Hello all.
I am diving into Ruby and documenting my steps along the way. So far so good, getting caught up with online tutorials and finding out what makes Ruby tick (so to speak).

A little bit about me:
My name is Stephen. I am currently residing in Lexington, Ky with my wife, Kelli and two dogs: Harley and Gracie. I work at Lexmark as a software engineer, designing test tools for the solutions department. My programming background is diverse, including C++, Java, C#, Python, PHP, and Javascript. I am learning Ruby partially due to curiosity and the Rails web application development.