[#73707] [Ruby trunk Misc#12004] Code of Conduct — hanmac@...
Issue #12004 has been updated by Hans Mackowiak.
3 messages
2016/02/05
[#73730] [Ruby trunk Feature#12034] RegExp does not respect file encoding directive — nobu@...
Issue #12034 has been updated by Nobuyoshi Nakada.
3 messages
2016/02/07
[#73746] [Ruby trunk Feature#12034] RegExp does not respect file encoding directive — nobu@...
Issue #12034 has been updated by Nobuyoshi Nakada.
3 messages
2016/02/09
[#73919] [Ruby trunk Feature#11262] Make more objects behave like "Functions" — Ruby-Lang@...
Issue #11262 has been updated by J旦rg W Mittag.
3 messages
2016/02/22
[#74019] [Ruby trunk Bug#12103][Rejected] ruby process hangs while executing regular expression. — duerst@...
Issue #12103 has been updated by Martin D端rst.
3 messages
2016/02/27
[ruby-core:73754] [Ruby trunk Feature#12059] `Array#single?`, `Hash#single?`
From:
nobu@...
Date:
2016-02-10 02:11:29 UTC
List:
ruby-core #73754
Issue #12059 has been updated by Nobuyoshi Nakada.
`[1, false, nil].one?` also returns `true`.
From `ri Enumerable#one?`:
------------------------------------------------------------------------------
enum.one? [{ |obj| block }] -> true or false
------------------------------------------------------------------------------
Passes each element of the collection to the given block. The method returns
true if the block returns true exactly once. If the block is not given, one?
will return true only if exactly one of the collection members is true.
%w{ant bear cat}.one? { |word| word.length == 4 } #=> true
%w{ant bear cat}.one? { |word| word.length > 4 } #=> false
%w{ant bear cat}.one? { |word| word.length < 4 } #=> false
[ nil, true, 99 ].one? #=> false
[ nil, true, false ].one? #=> true
----------------------------------------
Feature #12059: `Array#single?`, `Hash#single?`
https://bugs.ruby-lang.org/issues/12059#change-56940
* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
There are some use cases when one wants to check if an array or a hash has exactly one element. I propose `Array#single?` and `Hash#single?` that checks for such cases and returns either `true` or `false`. This is an analogy from the `empty?` method on the respective class.
* When creating an inflectional form out of an array:
~~~ruby
a = ["object1", "object2"]
"There #{a.single ? "is" : "are"} #{a.length} #{a.single? ? "object" : "objects"}."
# => "There are 2 objects."
~~~
* When checking if all elements of the array are the same:
~~~ruby
[1, 2, 2, 1].uniq.single? # => false
[1, 1, 1, 1].uniq.single? # => true
~~~
--
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>