Saturday, August 22, 2009

Ruby


Ruby

Hi every one, how r u,

Today we are going to talk about Ruby programming.

Ever heard about ruby programming language??

Ever know why does it make the best language for a lot of us??

Ever you wrote a code in one of the platform and copied the same code on another platform and run with out any changes??

Why Ruby??

So, let's talk little about Ruby.

Ruby is one of the best programming languages for me why I said that??

It's an open source language which has adapted to run on many different computer platforms and architectures. This means that if you develop a Ruby program on one machine, it’s likely you’ll be able to run it without any changes on a different machine. You can use Ruby, in one form or another, on all the following operating systems and platforms:

• Microsoft Windows 95, 98, XP, Vista, and Windows 7

• Mac OS X

• Linux

• Sun Solaris or Open Solaris

• BSDs (including FreeBSD and OpenBSD)

• Symbian Series 60 platform (cell phones, typically)

• Any platform for which a full Java Virtual Machine exists (using JRuby)

That's why ruby is one of the best programming languages.

What about coding? Really sample to learn.

Let's begin with installing Ruby in different operating system.

Windows:

1. Open a web browser and go to http://www.ruby-lang.org/en/downloads/.

2. Scroll down to the Ruby on Windows section, about halfway down the page.

3. In the Ruby on Windows section, you’ll see a few links for different versions of Ruby you can download for Windows. Ideally, you want to download the file at the link that’s highest in the list that’s referred to as a “One-Click Installer.” At the time of writing, this is version 1.8.6 (though it may be 1.9.1 or higher when you read this).

4. Click the link from step 3 and run the downloaded file to launch the installer. The file is approximately 20 MB in size, so it may take a while to download.

5. If Windows gives you a “Security Error” box, click the “Run” button to give your

approval.

6. A typical installation program appears with some instructions. On the initial screen,

click “Next.”

7. Work your way through the installation screens. Leave the boxes checked to install

The text editor SciTE and the Ruby package manager Ruby Gems (more on that in

Chapter

7. Unless you have a specific reason not to, let the installation program install

Ruby in its default location of c:\ruby and its default program group.

8. Installation takes place when you see a stream of filenames flying up your screen. Wait several minutes for the installation process to complete, and enjoy the view. There are a lot of files to install!

9. Installation is complete when the installation program says “Installation Complete”

And the “Next” button is clickable. Click the “Next” button, and then click “Finish” to exit the installation program.

After that click start>>run>>cmd in the command line and enter.

Write C:\Ruby\bin\irb and press enter, it will be like that:

So u r ready to code :).

Linux:

As an open source programming language, Ruby is already installed with many Linux distributions.

It’s not universal, though, but you can check if Ruby is installed by following the

Instructions in the next section. If this fails, there are further instructions to help you install it.

Checking If Ruby Is Installed on Linux

Try to run the Ruby interpreter from the command prompt (or terminal window), as follows:

Ruby –v

If Ruby is installed, it will give an output such as the following:

Ruby 1.8.6 (2007-09-23 patchlevel 110) [i686-linux]

This means that Ruby 1.8.6 is installed on the machine. This post requires 1.8.2 as a bare minimum, so if the version is earlier than 1.8.2, you’ll need to continue onward in this chapter and install a more recent version of Ruby. However, if Ruby appears to be installed and up to date, try to run the irb interactive Ruby interpreter, as follows:

irb

Once you’ve run irb, you should get the following output:

irb(main):001:0>

If running irb results in a similar output you can code now.

Installing Ruby with a Package Manager

The installation procedure for Ruby on Linux varies between different Linux distributions.

Some distributions, such as Gentoo, Debian, and Red Hat, provide “package managers” to make installation of programs easy. Others require that you install directly from source or install a package manager beforehand.

If you’re comfortable with using emerge, rpm, or apt-get, you can install Ruby quickly with the following methods:

Yum (on RedHat, CentOS, and Fedora): Install as follows: yum install -y ruby and

then yum install -y ruby-devel ruby-docs ruby-ri ruby-irb ruby-rdoc.

Gentoo: Use emerge as follows: emerge ruby.

Debian and Ubuntu: Use apt-get, as such: sudo apt-get install ruby1.8 ruby1.8-dev

ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8.

If one of these methods works for you, try to run Ruby and irb as shown in the preceding section, and progress to Chapter 2 if you’re ready. Alternatively, you can search your distribution’s package repository for Ruby, as the name for the Ruby package in your distribution might be nonstandard or changing over time. However, if all else fails, you can install Ruby directly from its source code in the next section.

Coding:

Coding with Ruby like writing English with small different if y need to write a string on the screens it's like:

Puts "what ever u want".

And press enter.

Try that one 1+1 and press enter.

What about arrays? If u need to define array all u need is to write

x= [1, 2, 3, 4], and press enter.

Try to write x.length it would like 4 and so one.

It's one of the sample and interesting languages J

Hope u enjoy today.

See u :).

No comments:

Post a Comment