Feature #12306

Implement String #blank? #present? and improve #strip and family to handle unicode

Added by sam.saffron (Sam Saffron) almost 5 years ago. Updated over 2 years ago.

Target version:


Time and again there have been rejected feature requests to Ruby core to implement blank and present protocols across all objects as ActiveSupport does. I am fine with this call and think it is fair.

However, for the narrow case of String having #blank? and #present? makes sense.

  • Provides a natural extension over #strip, #lstrip and #rstrip. (" ".strip.length == 0) == " ".blank?

  • Plays nicely with ActiveSupport, providing an efficient implementation in Ruby core: see:, implementing blank efficiently requires a c extension.

However, if this work is to be done, #strip and should probably start dealing with unicode blanks, eg:

irb(main):008:0> [0x3000].pack("U")
=> " "
irb(main):009:0> [0x3000].pack("U").strip.length
=> 1

So there are 2 questions / feature requests here

  1. Can we add blank? and present? to String?
  2. Can we amend strip and family to account for unicode per:

Related issues

Related to Ruby master - Feature #8110: Regex methods not changing global variablesClosedmatz (Yukihiro Matsumoto)Actions
Related to Ruby master - Feature #12403: Optimise Regexp#match?OpenActions
Is duplicate of Ruby master - Feature #8206: Should Ruby core implement String#blank? OpenActions

Also available in: Atom PDF