Home A concise explanation of nil v. empty v. blank in Ruby on Rails
Reply: 0

A concise explanation of nil v. empty v. blank in Ruby on Rails

user767
1#
user767 Published in May 28, 2018, 9:46 am

I find myself repeatedly looking for a clear definition of the differences of nil?, blank?, and empty? in Ruby on Rails. Here's the closest I've come:

  • blank? objects are false, empty, or a whitespace string. For example, "", " ", nil, [], and {} are blank.

  • nil? objects are instances of NilClass.

  • empty? objects are class-specific, and the definition varies from class to class. A string is empty if it has no characters, and an array is empty if it contains no items.

Is there anything missing, or a tighter comparison that can be made?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 1.006302 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO