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

Add #empty? to Tempfile, StringIO, File::Stat #1759

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mikegee
Copy link

@mikegee mikegee commented Nov 16, 2017

Rubocop prefers empty? over length == 0 and size == 0, which is great for String, Array, Hash, etc. It would be nice if more classes implemented #empty? for consistency.

See related discussion at rubocop/rubocop#2841

https://bugs.ruby-lang.org/issues/14136

@mikegee
Copy link
Author

mikegee commented Nov 16, 2017

I couldn't find where to add tests for File::Stat#empty?, but that one just an alias. Maybe it isn't valuable enough to test it. ¯\_(ツ)_/¯

rb_raise(rb_eIOError, "not opened");
}
long len = RSTRING_LEN(string);
if (len == 0) { return Qtrue; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since len is not used anywhere else but that if, can this be equivalent?

if (RSTRING_LEN(string) == 0) { return Qtrue; }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

@Drenmi
Copy link

Drenmi commented Sep 12, 2018

Would love to see this merged in the name of 🦆 typing. 🙂

@bbatsov
Copy link

bbatsov commented Sep 12, 2018

Same here.

@k0kubun k0kubun changed the base branch from trunk to master August 15, 2019 17:36
k0kubun added a commit to mikegee/ruby that referenced this pull request Aug 17, 2019
Rubocop prefers `empty?` over `length == 0` and `size == 0`, which is great for String, Array, Hash, etc. It would be nice if more classes implemented `#empty?` for consistancy.

See related discussion at rubocop/rubocop#2841
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants