方法
实例公共方法
blank?() 连结
nil
是空白
nil.blank? # => true
@return [true]
来源:显示 | 在 GitHub 上
# File activesupport/lib/active_support/core_ext/object/blank.rb, line 56 def blank? true end
to_param() 连结
回报 self
。
来源:显示 | 在 GitHub 上
# 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)
来源:显示 | 在 GitHub 上
# File activesupport/lib/active_support/core_ext/object/try.rb, line 148 def try(*) nil end
try!(*) 连结
对 nil
呼叫 try!
总是回报 nil
。
nil.try!(:name) # => nil
来源:显示 | 在 GitHub 上
# File activesupport/lib/active_support/core_ext/object/try.rb, line 155 def try!(*) nil end