Project

General

Profile

Feature #13933

Add Range#empty?

Added by ted (Ted Johansson) about 2 years ago. Updated about 2 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:82948]

Description

Range already responds to #size. It would be nice if it also responded to predicate #empty? :-)

History

Updated by marcandre (Marc-Andre Lafortune) about 2 years ago

Note that Range#size currently returns nil for ranges of string, so it's not clear what empty? would return for ranges of strings.

Updated by shan (Shannon Skipper) about 2 years ago

Range mixes in Enumerable so you can use #none?.

('a'..'b').none? #=> false
('b'..'a').none? #=> true

Updated by shevegen (Robert A. Heiler) about 2 years ago

I think the semantics between ".none?" is not the same as ".empty?". At
the least the latter appears to be more explicit to me.

But it's also not that important to me personally, I am fine either way. :-)

Also available in: Atom PDF