Ruby Basics Page

Ruby is a dynamic programming language that has recently gained some popularity, mainly due to Rails framework, which is for Ruby programming language. The beauty of Rails is that it lets to do web development in faster time. (At least according to the literature).Lets do a quick start by installing Ruby first; in subsequent posts, I would assume that you already have Ruby installed with all things in place. First things first, you can download Ruby Ruby Installer.

As I always, lets dive into sort of black box programming (by black box, i mean without actually understanding internals of Ruby). So I’ll start by writing a small program that converts centigrade to Fahrenheit. (I know, its trivial but i am guessing it should give you some idea). Things you must know before hand is, that Ruby is interpreted language. You can use Notepad (I use Notepad++) to create Ruby files, Ruby files end with *.rb extension. For clarity, Ruby is a programming language, There is no such thing as RUBY (there’s no full form as it isn’t an acronym).

print(”Enter a Centigrade Value –> “);
c = gets; # note you can define this in one line print(”Enter a centigrade value to convert:”,c = gets”);
# or even shorter and more denser version print(”Enter a centigrade value to convert to F ——> “, gets.to_i * 9 / 5 ) + 32
# (haha, you can see that I am a java guy obviously as i am still doing semi colons)
f = (c.to_i * 9 / 5) + 32
print(”The result is –>”, f)


Let’s break the code down;

Well, save this file and call it something (any name would do), and get ready to see results. (It’s not rocket science to run this through believe me :) ).

Output :
There you go, we just made our first Ruby program!
More to follow, stay tuned guys!
Click here for Output of above !
Regards
Vyas, Anirudh