Issue #12075 has been updated by Robert A. Heiler.


Perhaps the name .contains? might be good?

Although, .include? sort of is more or less synonymous with .contains? so perhaps this is not a good choice either.

.nonempty? seems a bit long, .non_empty? would be even longer :)

.empty? is a very good name already, I am not sure if "! .empty?" has a good name, though ruby uses the keyword "not"
already. Could use .notempty? haha sorry, I have no good suggestion for a fitting name for negation either, but I am
totally fine with the idea and functionality of the proposal itself, it's a good one.

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57061

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can”Ēt be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>