[ruby-core:114907] [Ruby master Feature#13933] Add Range#empty?

Issue #13933 has been updated by Dan0042 (Daniel DeLorme). akr (Akira Tanaka) wrote in #note-14:
Float::NAN is not comparable with anything else, not only floats.
Sorry, maybe I didn't express myself well, I meant that floats are usually comparable with other floats, with the exception of NaN. Whereas one `Object.new` is never comparable with another `Object.new`
I described an idea in https://bugs.ruby-lang.org/issues/19839#note-18 : `minimum?` method.
I feel `empty?` can sometimes be a wrong name. `minimum?` represent the property directly.
Yes, `minimum?` is cleaner and "the right way"; `empty?` is more like a hack that works with existing builtin classes with no changes needed. All 3 options you described are perfectly fine.
I think a bug report like my comment will coming someday. Ruby developers (especially matz) need to respond to it.
By "not worth worrying too much" I did not mean we should ignore or postpone it. I just meant we can pick *any* of the options without worrying too much about getting the perfect one. * `empty?` method * `minimum?` method * `MINIMUM` constant * hard code minimum values * document the limitation (even this, while not ideal, is "good enough" imho) * a mix of the above (ex: hardcode for builtins, `minimum?` method for user-defined classes)
Also, this problem can be expanded if we introduce `Range#exclude_begin?` (with neko operator). https://bugs.ruby-lang.org/issues/12133 In that case, we need `maximum?` as well. But we also need a method to check the existence between two objects because `[1] ^..^ [1, ""]` is empty (no objects between `[1]` and `[1, ""]`).
Huh, "neko" operator... that's cute 🐱 ---------------------------------------- Feature #13933: Add Range#empty? https://bugs.ruby-lang.org/issues/13933#change-104774 * Author: ted (Ted Johansson) * Status: Open * Priority: Normal ---------------------------------------- Range already responds to #size. It would be nice if it also responded to predicate #empty? :-) -- https://bugs.ruby-lang.org/
participants (1)
-
Dan0042 (Daniel DeLorme)