[#82706] [Ruby trunk Bug#13851] getting "can't modify string; temporarily locked" on non-frozen instances — cardoso_tiago@...
Issue #13851 has been updated by chucke (Tiago Cardoso).
3 messages
2017/09/07
[#82853] [Ruby trunk Bug#13916] Race condition when sending a signal to a new fork — russell.davis@...
Issue #13916 has been reported by russelldavis (Russell Davis).
3 messages
2017/09/19
[#82892] [Ruby trunk Bug#13921] buffered read_nonblock doesn't work as expected using SSLSocket — cardoso_tiago@...
Issue #13921 has been updated by chucke (Tiago Cardoso).
3 messages
2017/09/20
[ruby-core:82600] [Ruby trunk Bug#13855] Hash#compact! returns nil if the hash is empty
From:
duerst@...
Date:
2017-09-01 02:28:57 UTC
List:
ruby-core #82600
Issue #13855 has been updated by duerst (Martin Dürst).
Assignee set to nobu (Nobuyoshi Nakada)
`nil` is returned if there is no change, not only if the hash is empty:
```
hash = { foo: :bar, one: :two } # => {:foo=>:bar, :one=>:two}
hash.compact! # => nil
```
This is consistent with many other bang methods. The idea is that the result is available in the changed variable already, and the return value can be used in an `if` or `while` expression.
The patch looks good, I hope Nobu can apply it (I can't automatically integrate patches from github).
----------------------------------------
Bug #13855: Hash#compact! returns nil if the hash is empty
https://bugs.ruby-lang.org/issues/13855#change-66423
* Author: elandesign (Paul Smith)
* Status: Open
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version:
* ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
This behaviour feels like a bug to me.
From the documentation (with my emphasis):
> compact! → hsh
> Removes all nil values from the hash. **Returns the hash**.
However if the hash contains no keys, the method returns nil.
~~~
irb(main):001:0> {}.compact!
=> nil
# For Comparison
irb(main):002:0> { foo: nil }.compact!
=> {}
irb(main):003:0> {}.compact
=> {}
irb(main):004:0> { foo: nil }.compact
=> {}
~~~
--
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>