略过内容 跳至搜索
方法
B
T

实例公共方法

blank?()

nil 是空白

nil.blank? # => true

@return [true]

# File activesupport/lib/active_support/core_ext/object/blank.rb, line 56
def blank?
  true
end

to_param()

回报 self

# File activesupport/lib/active_support/core_ext/object/to_query.rb, line 20
def to_param
  self
end

try(*)

nil 呼叫 try 总是回报 nil。当导航关联关系时特别有用,而可能回报的关联关系为 nil

nil.try(:name) # => nil

不使用 try

@person && @person.children.any? && @person.children.first.name

使用 try

@person.try(:children).try(:first).try(:name)
# File activesupport/lib/active_support/core_ext/object/try.rb, line 148
def try(*)
  nil
end

try!(*)

nil 呼叫 try! 总是回报 nil

nil.try!(:name) # => nil
# File activesupport/lib/active_support/core_ext/object/try.rb, line 155
def try!(*)
  nil
end