Skip to content

Use of defined? returns truthy value on nil #46

@keithrbennett

Description

@keithrbennett

For the methods whose names end with ?, do you maybe want to test for nil rather than test to see if the variable is defined? That is, you want the method to return false if it is defined as nil, right?

For example:

def stream?
  defined? @stream
end

Would this be better off as the following?:

def stream?
  !! @stream
end

I use !! because I find it helpful for methods ending with ? to return true or false, rather than truthy or falsy values. I feel it is more precise, and produces clearer and more concise output when logging/debugging using expressions like puts "stream? == #{foo.stream?}".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions