.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 Concise and Practical Introduction to Programming Algorithms in Java》由Frank Nielsen编写,涵盖了算法的基础知识及其实现方法。 - 作者Frank Nielsen在算法领域具有丰富的经验和深厚的专业背景,...
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 ...
sap press doc 解压密码:abap_developer
"concise-0.3.4.tar.gz"就是这样一个从PyPI官网下载的Python库的压缩包文件,其版本号为0.3.4。 "concise"这个名字可能暗示该库的设计理念是简洁、高效,可能提供了一种简单的方式来处理特定的编程任务。在Python...
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 ...
在"A Concise Introduction to MATLAB.zip"这个压缩包中,很可能是包含了对MATLAB的初级到中级的教程资料,包括基础概念、语法讲解、实例演示等内容,旨在帮助初学者快速掌握MATLAB的基本用法和编程技巧。...
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 overview provides a detailed look into the key concepts and features of the Ruby programming language covered in the "Ruby Pocket Reference." It serves as a comprehensive guide for both beginners...
**All of Statistics: A Concise Course in Statistical Inference** 这本书从概率的基础概念入手,为读者构建了一个坚实的统计推断理论框架。 ##### 2. 概率 概率论是统计学的基础,这部分主要介绍概率的基本概念...
The "Ruby Pocket Reference" by Michael Fitzgerald is a concise and practical guide designed to serve as a quick reference for Ruby programmers. Published in its first edition in July 2007 by O'Reilly ...
I just got my hands on a copy, and the first few chapters have been fascinating."--Open Systems Today"A much more readable and detailed treatment of UNIX internals can be found in Advanced ...
action_access, 面向 Ruby on Rails的访问控制系统 操作访问 动作存取为模块,concise concise,真正收费使用访问控制系统的Access 。 它允许安全地保护应用程序和处理权限。关注当前用户可以访问的操作,而不是干扰...