From: bozhidar@... Date: 2018-09-12T05:12:10+00:00 Subject: [ruby-core:88955] [Ruby trunk Feature#14136] Implement #empty? on more classes Issue #14136 has been updated by bozhidar (Bozhidar Batsov). bozhidar (Bozhidar Batsov) wrote: > phluid61 (Matthew Kerwin) wrote: > > mikegee (Michael Gee) wrote: > > > > > > I am proposing that all classes that implement `#size` or `#length` should also implement `#empty?` to let developers write clearer code. > > > > This is one of the Rubocop cops I always disable, because I don't find #empty? conceptually clearer (or necessarily even accurate) unless that's what I wrote in the first place. > > > > `File.stat` is a perfect example: the status object isn't empty. Adding this method would make Ruby code *less* clear, more idiosyncratic. > > Yeah, in this case I'd argue that it's better to use some `top-level` methods of `File` instead, but in general every object that has the notion of size should also have the option of emptiness. That's common sense and not adhering it to in the default API simply frustrates Ruby developers everywhere. Also I'm curious who'd claim that adding an empty method doesn't make sense for something like `Tempfile` or `StringIO`. ---------------------------------------- Feature #14136: Implement #empty? on more classes https://bugs.ruby-lang.org/issues/14136#change-73988 * Author: mikegee (Michael Gee) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Hi Ruby Friends! 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 https://github.com/bbatsov/rubocop/issues/2841. I started this work at https://github.com/ruby/ruby/pull/1759 Thanks! -- https://bugs.ruby-lang.org/ Unsubscribe: