Rails Object#blank? vs. String#empty? confusion
Rails文档具有
An object is blank if it’s false, empty, or a whitespace string. For example,"","", nil, [], and {} are blank.
但该方法的来源是这样的:
1 2 3 4 | # File activesupport/lib/active_support/core_ext/object/blank.rb, line 12 def blank? respond_to?(:empty?) ? empty? : !self end |
现在,当我打开我方便的小命令行并输入
在理解Rails的
Rails在如何记录其
activesupport / lib / active_support / core_ext / object / blank.rb,第66行:
1 2 3 4 5 | class String def blank? self !~ /\S/ end end |