Roshan Book

My Tech Notebook

Learning Ruby – Part 1


I always wanted to learn Ruby. Ruby and Python has been at the forefront of dynamic language revolution adding support to the old warhorse “Lisp” . Lisp is going to be the final frontier for me, but after Python, I wanted to taste water of Ruby.

I have started awesome video tutorials by thenewboston.com and finished first three lessons , which basically talked about setting up ruby on windows machine, running irb and doing some simple maths. Notes which I am going to list henceforth would be combination of “my notes+thenewboston instructions+various books+web research” .

Setting up Ruby on windows machine

1. Bucky has recommended rubyinstaller, which can be downloaded from here . But I have earlier came across another great installer called rails installer. It will set up everything for you,along with the rails support. So you don’t need to install anything , even if you decide to go with rails development later. You could get rails installer from here .

IRB

IRB is default console based program for playing with ruby code. Go to start>>type irb>>launch

Run simple math

Type 1+2 and hit enter. If you get ” =>3″ , you are ready to go to next lesson

Few Points to remember

Ruby considers new line, or ; as end of statement. If it detects + or / or – at end of line it considers it as continuation of statement.

Reserved Keywords in Ruby

BEGIN do next then
END else nill true
alias elsif not undef
and end or unless
begin ensure redo until
break false rescue when
case for retry while
class if return while
def in self __FILE__
defined? module super __LINE__

Ruby Begin statement, is the the set of codes which is run before running the program

Begin {}

Similarly Ruby End statement, are the codes which is run after program is ended

End {}

Comments are declared in Ruby with #

# I am a comment

To write several lines of comments we follow following syntax

=begin

comment 1

comment 2

=end

Another way for multi-line string is

tunam=<<mark

“line 1

“line 2

“mark

And it will print line  1 and line 2 in new line

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: