Hashes & symbols Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

nil

A

returned if you try to access a hash key that does not exist.

Similar to false, but nil means nothing at all

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

symbols

A

Symbols must be valid Ruby variable names and always start with a colon (:).

In Ruby, symbols are immutable names primarily used as hash keys or for referencing method names.

my_bologna = {
  :first_name => "Oscar",
  :second_name => "Meyer",
  :slices => 12
}

puts my_hash[:second_name] # => Meyer

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

.to_sym

A

converts a string to a sympol

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

.to_s

A

converts a symbol to a string

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

.intern

A

converts a string into a symbol

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

symbol syntax

A

symbol:

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

.select

A

used to filter for a hash that meets a specified criteria

grades = { alice: 100,
  bob: 92,
  chris: 95,
  dave: 97
}
grades.select { |name, grade| grade <  97 }
# ==> { :bob => 92, :chris => 95 }
grades.select { |k, v| k == :alice }
# ==> { :alice => 100 }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

.each_key

A

iterates over only the keys of a hash

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

.each_value

A

iterates over only the values of a hash

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

when

A

acts as an If

i.e.

case choice
  when "add"
    puts "Added!"
  when "update"
    puts "Updated!"
  when "display"
    puts "Movies!"
  when "delete"
    puts "Deleted!"
  else
    puts "Error!"
end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

.to_i

A

converts a string to an integer

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

.delete

A

deletes a key/value from a hash

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

CRUD

A

acronym for create (add), display, update, delete.

Common actions you take when updating a database, asking a website for information, or writing a blog post.

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