Ruby Cheatsheet - Jesus Castello Flashcards

1
Q

Strings

A

A string is a sequence of characters inside two quotation marks (“”). Used to represent text & data. Also can use single quotation marks (‘’).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Important methods for Strings

A
  • size
  • empty?
  • include?
  • gsub
  • split
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Hashes

A

A hash ( {} ) is a key-value pair ( a => b) data structure. Used as a dictionary. You can access hash elements by their keys. Keys are unique.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Important methods for hashes

A
  • key?
  • fetch
  • new (for default value)
  • merge
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Hash example

A
#Create
h = { a: 1, b: 2, c: 3 }
#Access
h[:a]
# Set
h[:test] = 10
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Symbol

A

A static string used for identification, one common example is hash keys. They always start with a colon ( :bacon). Symbols are never used for their content (the individual characters).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

nil

A

A singleton class (only one object allowed) that represents a default or “not found” kind of value.

Evaluates to “false” in a conditional context.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Array

A

An object used to represent a list of objects. An array can contain any kind of object ( a = [1, “abc”, []] ), including other arrays.

You access array elements with their index ( a[0] ) & nested arrays with a[0][0] .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Important methods for Array

A
  • size
  • empty?
  • push / pop
  • join
  • flatten
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Enumerable

A

A Ruby module used to iterate over the elements of any class that implements the each method, like Array, Range & Hash.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Important methods for Enumerable

A
  • map
  • select
  • inject
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Method count

A

exactly what the name says, count things that evaluate to true inside a block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

method map

A

Transforms every element of the enumerable object and returns the new version as an array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

FILE

A

A class that helps you work with files in Ruby. Anything from reading them, writing to them or even getting info about them, like the file size.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly