March 1st, 2009

Starting Back.

Alright, like the several posts before this, I’m going to say that I will be starting back blogging. Why not, I’ve got a lot to share, but lack the overall skill to share it, or at least that’s my opinion.

I’ll starting work on a side project with a friend of mine travis robertson . I think its a great idea, but I’m going to keep from sharing to much detail until we have a alpha/beta release.

Obviously, I’ve been working full time on Ruby on Rails projects since 2006, and working with ruby since 2005. I’m going to be working on this project with the hope that I’ll create something that I would use myself, and I think other’s will use it as well.

Now as suggest by my good friend Charles here is some Simple Ruby Code:

I’m sure you know those really wordy for loops in C-based languages in this case javascript.

1
2
3
4
5
6
7
8
9
10
var i=0;
for (i=0;<=10;i++)
 
{
 
document.write("The number is " + i);
 
document.write("");
 
}

ruby has a simple alternative.

1
11.times { |i| p "The number is #{i}\n" }

No that’s obviously simple, but there can be some confusion about what count i starts on. In the case of the .times method its starts on 0. However, there are other loops that you can have more control.

In ruby there is a trick with using arrays for loops.

1
[0,1,2,3,4,5,6,7,8,9,10].each {|i| p "The number is #{1}\n" }

Now obviously that seems a little odd, but will get the same result.
But ruby like everything has a shortcut using Ranges.

1
(0..10).each {|i| p "The number is #{1}\n" }

The number of ..dots matter in the above code. Two dots include the 10 in the loop, while 3 dots.

1
(0...10)

will only print 0-9.

Until next time.

One Response to “Starting Back.”

  1. Charles Says:

    I’m learning…something already

Leave a Reply