A screenshot of Ruby code featuring the #presence method, with text highlighting how it simplifies identifying `nil` values.

TWIL is our weekly series designed to foster a culture of continuous learning in software development. This week, Katie takes us through the elegantly simple intricacies of Ruby #presence, a nuanced method that sifts out the emptiness and returns either the value itself or nil.

Ruby #presence

Using thing.presence vs the truthiness/falsiness of thing directly: #presence returns the value or nil but importantly excludes empty values.

It is essentially just shorthand for thing.present? ? thing : nil.

# Empty string

> "" ? "truthy" : "falsy"
"truthy"

> "".present?
false

> "".presence
nil

# Empty array

> [] ? "truthy" : "falsy"
"truthy"

> [].present?
false

> [].presence
nil

# Non-empty string

> "thing" ? "truthy" : "falsy"
"truthy"

> "thing".present?
true

> "thing".presence
"thing"

# Non-empty array

> [1,2,3] ? "truthy" : "falsy"
"truthy"

> [1,2,3].present?
true

> [1,2,3].presence
[1, 2, 3]

# Nil

> nil ? "truthy" : "falsy"
"falsy"

> nil.present?
false

> nil.presence
nil

# True

> true ? "truthy" : "falsy"
"truthy"

> true.present?
true

> true.presence
true

# False

> false ? "truthy" : "falsy"
"falsy"

> false.present?
false

> false.presence
nil

Resources

  • Ruby
Katie Linero's profile picture
Katie Linero

Senior Software Engineer

Related Posts

AWS logo centered over dark blue stylized map of Europe with concentric radar-style rings emanating from Germany, representing the AWS European Sovereign Cloud infrastructure launch for EU data sovereignty and GDPR compliance
January 26, 2026 • Frank Valcarcel

AWS Launches European Sovereign Cloud

AWS launched a physically separate cloud infrastructure in Europe with EU-only governance, zero US dependencies, and over 90 services. Here is what organizations in healthcare, finance, and government need to know about the sovereign cloud and how to evaluate it for their compliance strategy.

MCP (Model Context Protocol) logo — a stylized white interlinked letter mark — centered on an abstract background of flowing purple and orange gradient waves, representing AI connectivity and data integration.
November 25, 2025 • Frank Valcarcel

Anthropic’s Model Context Protocol: The Standard for AI Tool Integration

A year after launch, Anthropic’s Model Context Protocol has become the universal standard for connecting AI agents to enterprise tools. Backed by OpenAI, Google, Microsoft, and the Linux Foundation. Here’s what developers need to know.

Let's work together

Tell us about your project and how Cuttlesoft can help. Schedule a consultation with one of our experts today.

Contact Us