Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of defined? returns truthy value on nil #46

Open
keithrbennett opened this issue Jan 29, 2017 · 1 comment
Open

Use of defined? returns truthy value on nil #46

keithrbennett opened this issue Jan 29, 2017 · 1 comment

Comments

@keithrbennett
Copy link

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?}".

abrom added a commit to abrom/henkei that referenced this issue May 10, 2017
Replaced used of `defined?` in source type boolean checks as per suggestion yomurb#46
Minor refactor
@abrom
Copy link

abrom commented May 10, 2017

Good catch @keithrbennett

I don't believe this project is still being maintained. I've forked it and applied your suggestion:

https://github.com/abrom/henkei/releases/tag/v1.14.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants