LEARNING RUBY: PART 1 | a GOOD PROGRAM!

Welcome brothers. So yesterday, I told you that I'm going to create a series on ruby language and this is my second post on it. In this post, I'll be making just a simple program as well as I'll tell you how to execute the code and I'll do some explanations. For making scripts, I'll be using nano text editor. Its just because its my choice and not mandatory, otherwise you can use whatever text editor you like.

LETS GET STARTED!

So, here we are. First of all, make a folder on your desktop or wherever you wish to store your practice files. Now open a text editor like this.

Now at the top, write #! /usr/bin/ruby. Why? Check out on the internet! If you have studied the posts made by (The Defalt) on python, you will know what it means. If you still don't get it, ask me then. Now enough talk, lets move further.

PUTS!!!

In your text editor type:
puts "Hello I'm using using ruby"
puts "It is very easy"
puts "You should learn it"
After typing this, your screen will look something like this.

Do not get confused if your text editor shows different color or not at all! Color is not important, the code is. If you are using gedit as a text editor, you can use color coding under the view/highlight and then selecting language.

So after that save you file with whatever name you wish and with .rb extension. After that, give it permissions to execute with:

chmod 755 <name of your file.rb>
and run it with ./<name of your file.rb>. It should look something like this.

Now, lets move further and go to comments.

COMMENTS!

A simple definition for comments will be Those strings which are not executed by the program are called comments. They are simply used by us to get the better understanding about what's going on in the code. For example, you want to review your code that you have written several years back. In those cases, comment comes in handy!

Comments are written using # at the first of the line. So go on and insert some of the comments in your code and see whether they do execute or not.If your comment is of more than one line, you can use =begin at the starting and =end at the end. If you have any problem regarding this, you can ask me in the comments section.

A side note: you cannot start your comment inside the string! Otherwise, they'll get executed. And by the string, I mean between "".

If you are not getting what I've said, don't worry, you'll get it later.

PRACTICE!

Here are some drills you can do to improve your knowledge.

  1. Go online and see what #! means.
  2. Search for the different types of comments used in other languages as well and compare it with yours.
  3. Use comments in your code.

Now that's all for today, have a nice day ahead! And don't forget to give feedback.

>>>DUSTY WORLD ///

Our Best Hacking & Security Guides

New Null Byte posts — delivered straight to your inbox.

2 Responses

!!!... Excellent Work Dusty Excellent ...!!!

  • Amazing work my bro ! Keep it Up...!!!! :)
  • Bro, You can use this: ' | ' instead of ' , ' in your main title after PART 1. Like this : Part #1 | a Good Program...! . But, Do as you wish, I'm just giving you an idea.

!!!... GOOD LUCK ...!!!

Share Your Thoughts

  • Hot
  • Active