There is 1 article on this title. You are reading the article ranked and rated #1 by Helium's members.
Ruby is a language, which, you will probably end up learning to love.
It is an Object-Oriented Language, which means that everything within Ruby is an object. An Object has properties (e.g. a watch is X heigh, Y width and Z depth etc) and it has methods (e.g. set an alarm, illuminate etc).
Ruby also takes some ideas from the Functional Programming Model. Functional Programming is a mathematical way to describe what a program should do (well known Functional Languages include Haskell, Miranda, ML and LISP). Ruby has limited functional support, but it is there none the less. I will not go into much detail about this, the best thing you could do if you want to know about this is look up topics such as Lambda Calculus, Closures and Blocks.
Finally, Ruby is also (typically) an interpreted language. The official version of Ruby and the Ruby libraries comes with a Ruby Interpreter (ruby on the command line), it also comes with the Interactive Ruby Shell (irb on the command line).
In true programming language tradition we start with the Hello World program. In Ruby this is nice and simple:
puts "Hello, World!"
That it, that's all it is. Lets analyse it a bit:
puts - this is a system level function which prints text to screen.
"Hello, World!" - this is an instance of the Ruby String class.
We can also put a number to screen:
puts 3
A little analysis shows that 3 is automatically assigned to the number class (more specifically Fixnum).
So lets now go on to outputting a number to screen and concatenate it with a string. You would imagine, it would look something like this:
puts 3 + "Is the magic number"
However we get this error:
TypeError: String can't be coerced into Fixnum
from (irb):5:in `+'
from (irb):5
This is a nasty looking error, but its basically saying that you can use the concatenate operator with different types (in this case a number type and a string type). This is because although Ruby is a dynamic typed language (a language that can assign types to variables when they are used), it is a strictly typed language (a language that has types that have rules).
As you can see, in Ruby types are important, even though you do not have to specifically say what type a particular variable is. This leads us on to variables. Variables can be assigned on the go. Using ruby we can say something like this:
magicNumber = 3
puts magicNumber
and 3 will be outputted to the screen. Simple, magicNumber becomes a Fixnum, and the ruby system knows how to show a simple number. Lets now go back to
Below are the top articles rated and ranked by Helium members on:
by Daniel Lewis
Ruby is a language, which, you will probably end up learning to love.
It is an Object-Oriented Language, which means that
Add your voice
Know something about The basics of Ruby?
We want to hear your view.
Write now!
Cast your vote!
Click for your side.
Featured Partner
Private Sector Solutions Network
Private Sector Solutions Network is a group of leaders working together to improve the world by developing and implem...more
hide