Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ruby
string
empty
communitycreator

What is string.empty? in Ruby?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The string.empty? function in Ruby returns a true value if the string is empty; otherwise, it returns false.

Figure 1 shows the visual representation of the string.empty? function.

Figure 1: Visual representation of string.empty? function

Syntax

string_name.empty?
# string_name is the name of the string

Parameter

This function does not require a parameter.

Return value

If the string is empty, the string.empty? function returns a true value. Otherwise, it returns false.

Example

The following code widget shows how the string.empty? function is used.

# string with value
str_1='Hello'

print "The string1('Hello') is empty : ", str_1.empty?, "\n"

# empty string
str_2 = ''

print "The string2('') is empty : ", str_2.empty?, "\n"
Implementation of string.empty? in Ruby

RELATED TAGS

ruby
string
empty
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring