In Ruby, the .empty? method is used to check whether a data structure, such as a string, array, or hash, is empty. It returns true if the object it is called on contains no elements or characters, and false otherwise.
Example:
# Strings
empty_string = ""
non_empty_string = "Hello, world!"empty_string.empty? # => true
non_empty_string.empty? # => false# Arrays
empty_array = []
non_empty_array = [1, 2, 3]empty_array.empty? # => true
non_empty_array.empty? # => false# Hashes
empty_hash = {}
non_empty_hash = { name: "John", age: 30 }empty_hash.empty? # => true
non_empty_hash.empty? # => false