Hashes Flashcards

1
Q

key?

A

common hash method that allows me to check if a hash contains a specific key. It returns a boolean.

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

select

A

this common hash method allows me to pass a block and will return any key-value pairs that evaluate to true when passed to the block.

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

fetch

A

common hash method that allows me to pass a given key and it will return the value for that key if it exists. I can also specify an option for return if that key is not present.
https://ruby-doc.org/core-2.1.0/Hash.html#method-i-fetch

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

to_a

A

a common hash method that returns an array version of your hash when called.

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

Hash

A

A data structure that stores items by associated keys. Contrasted to arrays which store items by index. Entries in a hash are often referred to as key-value pairs. Using symbols as keys and any data types as values.

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

Iterating over hashes

A

iterating_over_hashes.rb

person = {name: ‘bob’, height: ‘6 ft’, weight: ‘160 lbs’, hair: ‘brown’}

person.each do |key, value|
puts “Bob’s #{key} is #{value}”
end

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