.nil?
can be used on any object and is true if the object is nil
.empty?
can be used on strings, arrays and hashes and returns true if:
- String length == 0
- Array length == 0
- Hash length == 0
running .empty? on something that is nil will throw a NoMethodError
blank?()
An object is blank if it’s false, empty, or a whitespace string. For example, “”, “ ”, nil
, [], and {} are all blank.
This simplifies:
if address.nil? || address.empty?
…to:
if address.blank?
That is where .blank? comes in. It is implemented by Rails and will operate on any object as well as work like .empty? on strings, arrays and hashes.
nil.blank? == true
[].blank? == true
{}.blank? == true
"".blank? == true
5.blank? == false
.blank? also evaluates true on strings which are non-empty but contain only whitespace.
" ".blank? == true
" ".empty? == false
分享到:
相关推荐
Gong.Sheng-.Concise.Complex.Analysis.(World.Scientific,.Revised.ed..2007) 为djvu文档,请用软件DjVuLibre+DjView v3.5.22+v4.5阅读,地址:http://www.oschina.net/p/djvulibre
a very good algorithm book for java developers.
Title: A Concise Guide to Dynamic Web Application: WAMP/LAMP Author: Alasdair Gilchrist Length: 74 pages Edition: 1 Language: English Publication Date: 2015-03-04 ISBN-10: B00UAFGHY8 This ebook is a ...
Every concept is clearly explained alongside a full Ruby on Rails application deployment. You’ll also learn how to deploy via Docker using Amazon EC2 Container Service. What You Will Learn How to ...
sap press doc 解压密码:abap_developer
资源来自pypi官网。 资源全名:concise-0.3.4.tar.gz
A Concise Introduction to MATLAB.zip
This is the first CD-ROM edition of the Concise Encyclopedia of Mathematics CD-ROM by Eric W. Weisstein. It contains the entire contents of the hardcover edition of the CRC Concise Encyclopedia of ...
is concise book was intended to serve as a beginner’s guide for engineers, undergraduate seniors, and graduate students who seek a quick start on learning and/ or building deep learning systems of ...
This paper is a review of the evolutionary history of deep learning models. It covers from the genesis of neural networks when associationism modeling of the brain is studied, to the models that ...
个人博客主题wp-Concise-v1.0.txt
This concise introduction offers students and researchers an overview of the discipline that connects genetics and evolution. Addressing the theories behind population genetics and relevant empirical ...
Readers will find a concise explanation of the Relational Database Management System (RDBMS) model, a clear-cut explanation of foundational RDBMS concepts, and thorough coverage of basic SQL syntax ...
All of Statistics A Concise Course in Statistical Inference, 统计学景石教材
统计经典入门教材: All of Statistics: A Concise Course in Statistical Inference
A Concise Introduction to Languages and Machines.pdf
a very good text on statistical inference.
This open access Brief introduces the basic principles of control theory in a concise self-study guide. It complements the classic texts by emphasizing the simple conceptual unity of the subject. A ...
relatively concise definitions of statistical terms. All areas of statistics are covered, theoretical, applied, medical, etc., although, as in any dictionary, the choice of which terms to include and ...