Sunday, March 29, 2009

Lim Ding Wen

This boy' s pretty good! Read more about him in www.arnoldlim.wordpress.com if you want to see what fasinating about him.

Friday, March 13, 2009

New Gadget

Do you see that gadget just below my blog? That is one where we can type in anything related to Ruby, then it will tell you about it. No 'teddy bear' or 'crazy drunkard' because they are not related to Ruby.

Bye!

PS: There 's a gadget at the side of the blog that is named Dragonfable. That is my favourite game.

Tuesday, March 10, 2009

Arrays

An array is a list in Ruby. For example...

names = ['Max', 'Nancy', 'Lazy']

puts names(0)
puts names(1)
puts names(2)
puts names(3) #This is out of point

Anyway, if you don' t understand why names(3) is out of point, Ruby actually counts from 0. It will return 'nil' if you go out of point.

There' s lots of variables in arrays. I couldn't tell you all, so I' m going to quit this post now...

Friday, March 6, 2009

Creating New Methods

Creating new methods...hmm...not quite easy. I learned parameters and this word called 'def', which you need to use for creating methods. Here' s one method about factorials. You can copy them as there is no copyright sign there...

def factorial num
if num < 0
return 'You can\' t take the factorial of a negative number!' #Of course
end

if num <= 1 #If the number is greater than 1...
1
else
num * factorial (num-1) #It means num X (num-1) X (num-1-1)... and so on
end
end

#If you want to find the factorial of 10, put:

puts factorial(10)

Anyway, if you don' t know what are factorials, they are methods in Mathematics that when you want to find a factorial of a number, the number will be multiplied by the numbers before it. For example, the factorial of 5 is 120, which means that it is 5 x4x3x2x1. There will be no zero, 'cos if you put zero then every thing will be 0! The sign of factorials is !, and when you want to say the factorial of 23, then it will be 23!

Anyway, my Ruby book says that it is recursion. Here' s a other method...

def double_this num #The num is the parameter
num_times_2 = num*2
puts num.to_s+' doubled is '+num_times_2.to_s
end

#If you want to find 1938274 times 2...

double_this 1938274

And there you have it.

Friday, January 2, 2009

Learn to program by Chris Pine

This is the book that I use to learn Ruby. I can be for children and adults, and my father have an advertisment of it in his apple computer. No, I does not mean the red thing you eat for snacks! The Apple computer can be also called...erm...I don' t know the complete phrase, but the first word is 'Mac'.

Anyway, this book teaches you about making programs and not websites or games or rails for they are too hard and the book is for beginners.

By the way, I know that the second and third edition of the book! The second edition is 'Programming Ruby' and the third editon is 'Programming Ruby 1.9'. In case you did not know it, the Ruby version 1.9.0 is the lastest version of Ruby. But, the Ruby version in my computer is only 1.8.6, same as my Dad's.

By the way, look out for more post about my learning-Ruby experience!

Sunday, December 7, 2008

My First 9 Programs

Here are my first ten programs I created using Ruby:

  1. AngryBoss
  2. To Seventh Grade English
  3. How Many Seconds Old Are You
  4. Do you wet the bed
  5. TalkingWithGanster
  6. Intro to Ruby
  7. TheNumberOfCharactersInYourName
  8. Greeting
  9. The Fortune Teller