Skip to content

Instantly share code, notes, and snippets.

@TravisGM92
Last active May 27, 2020 14:05
Show Gist options
  • Save TravisGM92/269fc7bfa4fab4e0f14ad340f460b96e to your computer and use it in GitHub Desktop.
Save TravisGM92/269fc7bfa4fab4e0f14ad340f460b96e to your computer and use it in GitHub Desktop.
Beginners Guide to data types

Hi! This will be the first gist I've ever made on my own!

Let's talk about data types:

  1. Strings. Strings are some of the easiest data types. The only thing you need to do to indicate something is a string data type in Ruby is put it between quotes, either double (" ") or single quotes (' ').

  2. Integers. Or numbers, these are indicated in Ruby by just typing the number (not spelled out).

  3. Arrays. Arrays are nice, they allow you to tell Ruby that what follows is a list of elements I want to possibly manipulate later. I'll give two different examples of arrays;

  • Numbered arrays: [1, 2, 3, 4]
  • String arrays: ["George", "Travis", "Michael"]
  1. Hashes. Hashes are a bit more complicated, but the gist of hashes is; it's a list of items (called keys) with a corresponding value (usually number, but can be a string). An example of that would be someones favorite foods with their respective rating. Here's what that would look like;
"cookies" => 8,
"steak" => 9,
"peanut_butter" => 7

What I wrote above, in code, was: foods = Hash.new { key, value}.

Now you can try!

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment