Computer Nerds
  Ruby Tutorial
 
Computer Nerds

Ruby Tutorial


By: Admin


Ruby is one of the easiest programming languages ever devised. An example of the "Hello World" program is below:

puts "Hello World"

Yes it's that easy. If only all programming was that easy. Here I will show you how to program in the easiest programming language I have ever seen in my life.

To get started you need Ruby. To get it go here and download the One-Click installer. Once downloaded we will start with an easy version of the "Hello World" program. Go to Command Prompt by clicking "Start" and "Run." Type in cmd and click "Ok." In Command Prompt type irb for Interactive Ruby. It should eventually show something like: irb(main):001:0>. You may have to type something in if it doesn't show up. Once that happens type in the following: puts "(Whatever you want)". It should follow up with "(Whatever you put)"
=>nil
. When it responds =>nil it is saying that that command was correctly compiled. You do not need it in parenthesis, I just put it that way to show you how it can be virtually anything. You have now officially programmed in Ruby.

You may also easily use a calculator in Ruby. Simply type in a calculation. E.g. 4*4 would show =>16. To do square roots simply type in Math.sqrt(Whatever number). Now to add a variable we type in the following: a = 4*4. Then when the answer is displayed we type in: b = 4*5. And when that answer is displayed. Type in: a*b. And the answer should be 350.

It is also extremely simple to define a method. Simply do the following: def w
puts "(Whatever you want)"
end
. It should respond with =>nil. Now type in w and it should say: "(Whatever you put)"
=>nil
.

Let's try to say whatever to a person. To do that type the following, exactly:def w(name)
puts "Hello{#name}"
end
It should respond with =>nil. Now type in def w("Will"). It should say: Hello Will
=>nil
.

This tutorial will continue.

 
  There have been 33561 visitors (90801 hits) on this page! Owned and managed by: WCE  
 
=> Do you also want a homepage for free? Then click here! <=