From f1eff11255d14b0dcf059a46d48a71ea1ca11d78 Mon Sep 17 00:00:00 2001 From: qianchongyang Date: Sat, 21 Mar 2026 01:05:16 +0800 Subject: [PATCH] feat: add String#present? method Add present? method to String class that returns true if the string is not blank (i.e., !blank?). This matches the behavior of Rails' present? method and provides consistency with blank?. Fixes #16757 --- src/string.cr | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/string.cr b/src/string.cr index 940ba15f6602..c94dcdf459ab 100644 --- a/src/string.cr +++ b/src/string.cr @@ -3028,6 +3028,20 @@ class String true end + # Returns `true` if `self` is not `#blank?`. + # + # ``` + # "a".present? # => true + # "".present? # => false + # " ".present? # => false + # " a ".present? # => true + # ``` + # + # See also: `Object#blank?`. + def present? : Bool + !blank? + end + # Returns `self` unless `#blank?` is `true` in which case it returns `nil`. # # ```