Basics of Ruby: Part 1 (Data Types/Data Storage)

Aug 11, 2015 05:40 PM
Aug 11, 2015 05:55 PM
635748871438474519.jpg

Ruby is a dynamic, general-purpose programming language created by Yukihiro "Matz" Matsumoto in Japan around the mid-90's. It has many uses but with it's flexibility, it makes a great language to write exploits in. In fact, the entire Metasploit Framework is written in Ruby! The sole purpose of this series is to teach hackers the basics of Ruby, along with some more advanced concepts that are important in hacking.

Get Ruby

Before we can work with Ruby, we need to download it. Kali Linux, and most hacking distros have it preinstalled, but if you don't have it, use your package manager. For Ubuntu, you need to do the following:

sudo apt-get install ruby-full

This will download & install ruby

Data Types and Storage in Ruby

In Ruby, there are 4 data types:

1) Numbers (1,2,3,4,5...)

2) Strings ("Null Byte", "Ruby")

3) Boolean Values (true, false)

4) nil (Ruby version on Null)

Having all this information is great, but how are we going to use it if we can't store it? That is where the Data storage comes into place!

1) Variables

Variables are words/letters that hold some type of data. These are the simplest of the storage's. They are defined by putting the letter/word equal to a number, string, Boolean, or even a method! Examples:

635748872230662750.jpg

2) Arrays

Simply put, arrays are lists of different data. While variables hold only one value, arrays can hold however many you please of any data type you want. These are defined by a letter/word that are equal to brackets ([]). You can access the values by typing the array name along with the index of the value. For example:

635748872399410862.jpg

3) Hashes

Hashes are the Ruby equivalent to Python's dictionaries. They store a key/value pair. There are two ways to define them. The first way:

635748872813785038.jpg

The second way:

635748873069253479.jpg

You can access them by calling the name of the hash with the key in brackets...

635748873221597684.jpg

Next Time...

Basics of Ruby: Part 2 (loops) will be out sometime by the end of this week. I am becoming very busy as this is the last day of my summer break, but my plans have two lessons being published a week.

Comments

No Comments Exist

Be the first, drop a comment!