length_and_empty
📏 Checking Length and Emptiness
Use .length
(or .size
) to get the number of characters in a string, and .empty?
to quickly test if it contains nothing. These are useful for validation or conditional logic.
s1 = ""
s2 = "Hi"
puts s1.empty? # => true
puts s2.length # => 2