Data structures and algorithms are pretty much the heart and soul of programming. The whole point of writing code is to organize information, and manipulate it. This can become extremely complicated, and abstract, but you just have to start small. In order to understand data structures, you first have to understand data types. In ruby, there are basically 6 types of data – Booleans, Symbols, Numbers, Strings, Arrays, and Hashes.

Booleans

Booleans are the foundation of logic. A boolean either means true, or false.

Symbols

Symbols represent other objects. On their own, they are meaningless, but they can be used as more efficient representations of other things. This is a bit hard to explain in practical terms, until you get into the nitty gritty of using other data types.

Numbers

There are different kinds of numbers, and they can all be operated on mathematically. While there is a difference between an Integer and a Float (decimals), Ruby handily smooths those differences over, and allows you to use them interchangeably.

Strings

Strings are what you’re reading right now. Words, letters, even numbers can be strings. Anything with quotations around it. Strings can be operated on in a different way from numbers. You can search them, perform find/replace, capitalize, etc.

Arrays

An array is an ordered list. You can have an array of strings, numbers, booleans, or really any mixture of data types. Each item in an array has an index, starting with zero. An array of size 10 would have 10 items, numbered 0-9. Part of their purpose is to hold groups of items. You can sort those groups, or perform algorithms that operate on each item, or any number of things.

Hashes

Hashes are sort of like arrays in some ways. However, instead of just a list, they consist of key-value pairs. Basically they are sets of labels that have certain values. The keys are typically represented by symbols. This is another way to keep groups of data together, when you don’t care what order it’s in.

Putting it Together

Those are the data types – they help store all of the information. Manipulating those data structures to make things happen, or figure things out, is the essence of coding. You do that sort of thing using Algorithms, which may be the topic of a future post.