In Ruby, you check with nil? if an object is nil:
article = nil
article.nil? # => true
empty? checks if an element - like a string or an array f.e. - is empty:
# Array
[].empty? #=> true
# String
"".empty? #=> true
Rails adds the method blank? to the Object class:
An object is blank if it‘s false, empty, or a whitespace string. For example, “”, ” “, nil, [], and {} are blank.
This simplifies
if !address.nil? && !address.empty?
to
if !address.blank?
As of Rails 2.3, there’s also a handy new try() method on objects, which allows you to invoke a method on a possibly nil...
You can use HTML tags for formatting. Wrap code in <code> tags and multiple lines of code in <pre><code> tags.