Getting started with the ruby programming language, with a lot of examples and links to make things easier.
Ruby is a dynamic object oriented programming language, is focused in simplicity. Ruby is also multiplatform and open source. Here will see some basics, with some easy code examples.
First of all you have to install the Ruby platform for your OS
http://www.ruby-lang.org/en/downloads/
Install Netbeans IDE: It provides font highlighting, refactor, and code complete for ruby. I recommend netbeans but you can use notepad++, emacs or a simple text editor
Open Netbeans and make a new ruby project in the screen you will see the first aproach to every programing language.
Hello World
puts ”Hello World”
Output:
Hello World
If you add a multiplication.
puts ”Hello World” * 3
Ruby Output:
Hello WorldHello WorldHello World
Variables
In ruby you don’t have to declare variables, they are dinamically typed
word = “This is a String”
puts word.class
Ruby Output:
String
As you see it recognizes the word variable is a string, if you assign a number ruby will recognize it as a fixnum.
Types of variables in ruby
$variable = 1 #Global variable
@variable =1 #Instance variable
variable = 1 #local variable
Constant=1 #Constant
# means code commentary
Classes in ruby
def add(a,b)
a + b
end
value = add(1,2)
puts value
Ruby Output:
3
This is how you create classes in ruby, you can notice that is no “return” sentence. this is because ruby returns the last evaluated sentence “a+b”, you don’t have to declare data type like c or java.
Arrays in ruby
array = [1, "two", 3]
array.each { |item| puts item }
Ruby Output:
1
two
3
In Arrays you can store, every type of data yo see in the example you have two Fixnum and one String, the .each method print in the console each item in the array.
This is a little approach to ruby, it have a lot more. It really reduce time to market, but a interpreted language is slower than a compiled one, you have to see your problem, to make a good choice, ruby is a option.
Links :
http://en.wikipedia.org/wiki/Ruby_(programming_language)
Why (Poignant) guide to ruby (web book)
If you learn ruby you can also take a look to the web framework Ruby on rails. An example is creating a rails weblog in 10 minutes












8 Responses
You’re really good at this. Have you ever thought of writing tech manuals? The world needs people like you!
nice job as always xavix
http://www.authspot.com/Poetry/The-Last-Shot.441229
good work man,
very interesting for a tech loser like me!
cheers,
denus
You have a lot of information here. Great site.
Thanks for sharing, it’s always good to learn new things! cheers
Good… interesting..
another good article everyone is way advance
Its comprehensive and technical. Triond has a good collection of tech writers now