Skip to content

Instantly share code, notes, and snippets.

@Pragmaticpraxis37
Last active August 18, 2020 23:38
Show Gist options
  • Select an option

  • Save Pragmaticpraxis37/244122a1a86dad7f8760be489af7d9a3 to your computer and use it in GitHub Desktop.

Select an option

Save Pragmaticpraxis37/244122a1a86dad7f8760be489af7d9a3 to your computer and use it in GitHub Desktop.
Beginners Guide to data types

alt text

Documentation and Googling

Split string method

String split method is initiated by using the syntax .split at the end of a string object. An array is returned as a result of using the split method. If just .split is used, without parenthesis, it will return the string object in an array with each sub-string object being split out into an individual object inside of the array. The sub-strings are split off based off of the location of whitespace in the original string object. It is possible to modify how the original string is split by providing arguments to the .split.

  • For example: .split(//) will genreate an array that has each individual character in the original substring split off from the original string, including whitespace.
  • For example: "dog".split(//) will output ["d", "o", "g"].

Array slice method

Array slice method is initiated by using the syntax [] at the end of an array. A string, array, or nil is returned as a result of using the slice method, depending on the argument provided. An number is provided as an argument into the slice method. Multiple numerical arguments can be provided, including a range. If a signle number is provided, it will return an array with the element from the original array the corresponds to the number choosen.

  • For example: d = ["d", "o", "g"], d[2] will output d.

Google searches

  1. string split method: ruby-doc.org
  2. array slice method: ruby-doc.org

Data Types and variable assignment##

Micro Titans

String data:

p1 = "Microscopic" p2 = "Gigantic"

Integer and/or float data:

hit_points = 50 height_of_mountain = 14.5

Boolean data:

hit = true miss = false

Array data:

weapons = \["ray gun", "pie", "shrink ray"] landscapes = \["rivers", "mountains", "fields"]

Hash data:

starting_health = {"Microsopic" => 50, "Gigantic" => 50}

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