Hashes and symbols Flashcards

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

how to create a new hash?

A

my_hash = Hash.new
or
my_hash = {}

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

how to iterate through a hash?

A

my_hash.each do |key, value|
puts key, my_hash[key]
end

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

create a new hash with a default value “test”.

A

my_hash = Hash.new(“test”)

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

how to convert a string to a symbol and vice versa?

A

:mina.to_s

“mina”.to_sym or “mina”.intern

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

how to filer a hash for values that meet a certain criteria?

A

my_hash.select { |key, value| value

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

how to iterate through each key or each value only?

A

my_hash.each_key
or
my_hash.each_value

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

how to delete a pair from a hash?

A

my_hash.delete(“key”)

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