Hashes Flashcards
What is a hash?
what is a key in a hash?
in a hash there are “keys” that must be unique and cannot be duplicated. we use keys to store data in a hash.
explain .has_key?()
this method is used to find if there is a certain key inside a hash. you must call the key in the parameters. dog.has_key?(“name”)
explain .has_value?()
this used to find the value in a hash and it will return a boolean
explain hash.keys[] and hash.values[]
hash.keys is used to get all keys in an array. since its turned into an array you can call each array by providing an index.
hash.keys[1]
hash.values works exactly the same just targeting the values.
explain .each_key and .each_value
explain =>
this is what programmers call the rocket. it used to give value to a key in a hash
explain .Hash.new()
explain my_hash[“a”] => “yes”
what does this do?