Ruby: "if !object.nil?" or "if object"

ruby

Solution

There are differences. For example:

false.nil?
# => false

So:

if !false.nil?
  'foo'
end
# => "foo"

if false
  'foo'
end
# => nil

As @tokland suggested, in most cases using `!obj.nil?` construction is unnecessary.

Problem

Are they the same when used in an `if/else/end` statement? What do you usually do? I'm wondering if there are any subtle differences or edge cases where `object` and `!object.nil?` would respond differently.

Original source