1. [ ] - Returns the value associated with the specified key.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits["apple"]
    # Output: 2

2. [ ]= - Sets the value associated with the specified key.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits["apple"] = 5
    fruits
    # Output: {"apple"=>5, "banana"=>3, "orange"=>4}

3. each - Calls the block once for each key-value pair in the hash.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.each { |key, value| puts "#{key} has #{value} items" }
    # Output: 
    # apple has 2 items
    # banana has 3 items
    # orange has 4 items

4. each_key - Calls the block once for each key in the hash.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.each_key { |key| puts key }
    # Output: 
    # apple
    # banana
    # orange

5. each_value - Calls the block once for each value in the hash.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.each_value { |value| puts value }
    # Output:
    # 2
    # 3
    # 4

6. length or size - Returns the number of key-value pairs in the hash.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.length
    # Output: 3

7. empty? - Returns true if the hash contains no key-value pairs, false otherwise.

    fruits = {}
    fruits.empty?
    # Output: true

8. keys - Returns a new array containing all keys of the hash.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.keys
    # Output: ["apple", "banana", "orange"]

9. values - Returns a new array containing all values of the hash.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.values
    # Output: [2, 3, 4]

10. key? or has_key? - Returns true if the hash contains the specified key, false otherwise.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.key?("apple")
    # Output: true

11. value? or has_value? - Returns true if the hash contains the specified value, false otherwise.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.value?(2)
    # Output: true

12. delete - Deletes the key-value pair associated with the specified key and returns the value.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.delete("apple")
    # Output: 2

13. clear - Removes all key-value pairs from the hash.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.clear
    fruits
    # Output: {}

14. merge - Returns a new hash containing the contents of two hashes.

    fruits1 = { "apple" => 2, "banana" => 3 }
    fruits2 = { "orange" => 4, "grape" => 5 }
    fruits1.merge(fruits2)
    # Output: {"apple"=>2, "banana"=>3, "orange"=>4, "grape"=>5}

15. select - Returns a new hash containing only the key-value pairs for which the block returns true.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    large_fruits = fruits.select { |key, value| value > 3 }
    # Output: {"orange"=>4}

16. reject - Returns a new hash containing only the key-value pairs for which the block returns false.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    small_fruits = fruits.reject { |key, value| value > 3 }
    # Output: {"apple"=>2, "banana"=>3}

17. sort - Returns a new array of key-value pairs sorted by the keys.

    fruits = { "orange" => 4, "banana" => 3, "apple" => 2 }
    sorted_fruits = fruits.sort
    # Output: [["apple", 2], ["banana", 3], ["orange", 4]]

18. invert - Returns a new hash where the keys become the values and the values become the keys.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    inverted_fruits = fruits.invert
    # Output: {2=>"apple", 3=>"banana", 4=>"orange"}

19. transform_keys - Returns a new hash with the keys transformed by the block.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    uppercase_fruits = fruits.transform_keys { |key| key.upcase }
    # Output: {"APPLE"=>2, "BANANA"=>3, "ORANGE"=>4}

20. transform_values - Returns a new hash with the values transformed by the block.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    double_fruits = fruits.transform_values { |value| value * 2 }
    # Output: {"apple"=>4, "banana"=>6, "orange"=>8}

21. has_key? - Returns true if the given key is present in the hash, otherwise returns false.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.has_key?("banana")
    # Output: true

22. has_value? - Returns true if the given value is present in the hash, otherwise returns false.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.has_value?(5)
    # Output: false

23. key - Returns the key for the given value, or nil if the value is not found in the hash.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.key(2)
    # Output: "apple"

24. values - Returns an array of all values in the hash.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.values
    # Output: [2, 3, 4]

25. keys - Returns an array of all keys in the hash.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.keys
    # Output: ["apple", "banana", "orange"]

26. length - Returns the number of key-value pairs in the hash.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.length
    # Output: 3

27. empty? - Returns true if the hash contains no key-value pairs, otherwise returns false.

    fruits = {}
    fruits.empty?
    # Output: true

28. fetch - Returns the value for the given key. If the key is not found and a default value is not provided, raises a KeyError. If a default value is provided, returns the default value.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.fetch("banana")
    # Output: 3

    fruits.fetch("pear", "unknown")
    # Output: "unknown"

    fruits.fetch("pear")
    # Output: KeyError: key not found: "pear"

29. each - Calls the given block once for each key-value pair in the hash, passing the key and value as parameters.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.each do |key, value|
      puts "#{key} has a value of #{value}"
    end
    # Output:
    # apple has a value of 2
    # banana has a value of 3
    # orange has a value of 4

30. each_key - Calls the given block once for each key in the hash, passing the key as a parameter.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.each_key do |key|
      puts "#{key} is a fruit"
    end
    # Output:
    # apple is a fruit
    # banana is a fruit
    # orange is a fruit

31. each_value - Calls the given block once for each value in the hash, passing the value as a parameter.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.each_value do |value|
      puts "The fruit has a value of #{value}"
    end
    # Output:
    # The fruit has a value of 2
    # The fruit has a value of 3
    # The fruit has a value of 4

32. delete - Deletes the key-value pair for the given key from the hash and returns the value. If the key is not found, returns the default value if provided, or nil if not.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.delete("banana")
    # Output: 3

    fruits.delete("pear", "unknown")
    # Output: "unknown"

    fruits.delete("pear")
    # Output: nil

33. clear - Removes all key-value pairs from the hash.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.clear
    # Output: {}

34. invert - Returns a new hash with the keys and values inverted.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.invert
    # Output: {2=>"apple", 3=>"banana", 4=>"orange"}

35. merge - Returns a new hash containing the contents of the hash and the given hash. If a block is given, the block is called for each key that exists in both hashes, with the key, the value from the first hash, and the value from the second hash passed as parameters. The result of the block is used as the value for the merged hash.

    fruits1 = { "apple" => 2, "banana" => 3 }
    fruits2 = { "orange" => 4, "pear" => 5 }
    fruits1.merge(fruits2)
    # Output: {"apple"=>2, "banana"=>3, "orange"=>4, "pear"=>5}

    fruits1.merge(fruits2) { |key, value1, value2| value1 + value2 }
    # Output: {"apple"=>2, "banana"=>3, "orange"=>4, "pear"=>5}

36. select - Returns a new hash consisting of key-value pairs for which the block returns true.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4, "pear" => 5 }
    fruits.select { |key, value| value % 2 == 0 }
    # Output: {"apple"=>2, "orange"=>4}

37. select! - Similar to select, but modifies the hash in place by removing key-value pairs for which the block returns false.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4, "pear" => 5 }
    fruits.select! { |key, value| value % 2 == 0 }
    # Output: {"apple"=>2, "orange"=>4}

    # fruits has been modified in place
    puts fruits
    # Output: {"apple"=>2, "orange"=>4}

38. reject - Returns a new hash consisting of key-value pairs for which the block returns false.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4, "pear" => 5 }
    fruits.reject { |key, value| value % 2 == 0 }
    # Output: {"banana"=>3, "pear"=>5}

39. reject! - Similar to reject, but modifies the hash in place by removing key-value pairs for which the block returns true.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4, "pear" => 5 }
    fruits.reject! { |key, value| value % 2 == 0 }
    # Output: {"banana"=>3, "pear"=>5}

    # fruits has been modified in place
    puts fruits
    # Output: {"banana"=>3, "pear"=>5}

40. keep_if - Similar to select!, but modifies the hash in place by removing key-value pairs for which the block returns false.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4, "pear" => 5 }
    fruits.keep_if { |key, value| value % 2 == 0 }
    # Output: {"apple"=>2, "orange"=>4}

    # fruits has been modified in place
    puts fruits
    # Output: {"apple"=>2, "orange"=>4}

41. delete_if - Similar to reject!, but modifies the hash in place by removing key-value pairs for which the block returns true.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4, "pear" => 5 }
    fruits.delete_if { |key, value| value % 2 == 0 }
    # Output: {"banana"=>3, "pear"=>5}

    # fruits has been modified in place
    puts fruits
    # Output: {"banana"=>3, "pear"=>5}

42. empty? - Returns true if the hash has no key-value pairs.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.empty?
    # Output: false

    fruits = {}
    fruits.empty?
    # Output: true

43. has_key? or key? - Returns true if the hash contains the given key.

    fruits = { "apple" => 2, "banana" => 3, "orange" => 4 }
    fruits.has_key?("apple")
    # Output: true

    fruits.key?("pear")
    # Output: false

44. has_value? or value? - Returns true if the hash contains the given value.

    h = { "a" => 100, "b" => 200 }
    h.value?(100)   #=> true
    h.value?(999)   #=> false