Today I Learned

A Hashrocket project

Ready to join Hashrocket? Find Openings here and apply today.

ActiveSupport has a presence method

If you use ActiveSupport you have access to the method #presence that returns nil if the object is #blank?

require "active_support"

# blank? on String is a regex for /[:space:]*/
"\n\t \n\r".presence
=> nil

"     abc   ".presence
=> "     abc   "
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket, and we'd love to take a look at your project. Contact us and find out how we can help you.