新手问题 blank?,present?

542307299 · June 24, 2013 · Last by 542307299 replied at June 24, 2013 · 4036 hits

blank?,present?这俩具体啥意思,谁能详细给说说,三克油。

balnk?

An object is blank if it’s false, empty, or a whitespace string. For example, “”, “ ”, nil, [], and {} are all blank.

present?

An object is present if it’s not blank?.

http://api.rubyonrails.org/

#1 楼 @karma rma 你好,是不是当是空,nil,false 的时候是 blank;当非(空,nil,false)的时候返回 present?

# File activesupport/lib/active_support/core_ext/object/blank.rb, line 14
  def blank?
    respond_to?(:empty?) ? empty? : !self
  end
# File activesupport/lib/active_support/core_ext/object/blank.rb, line 19
  def present?
    !blank?
  end

#3 楼 @ywjno 非常感谢,看明白了。

#4 楼 @Rei 非常感谢,帮我好几次了,谢谢

You need to Sign in before reply, if you don't have an account, please Sign up first.