ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:98486] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc`.
@ 2020-05-23  2:15 samuel
  2020-05-23  2:26 ` [ruby-core:98487] " merch-redmine
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: samuel @ 2020-05-23  2:15 UTC (permalink / raw)
  To: ruby-core

Issue #16908 has been reported by ioquatix (Samuel Williams).

----------------------------------------
Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`.
https://bugs.ruby-lang.org/issues/16908

* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I don't have any strong opinion about this, but I observed the following behaviour which I thought was confusing. Maybe it's okay, or maybe we should change it to be more consistent.

```
hash = Hash.new{|k,v| k[v] = 0}

hash.shift # => 0
hash.shift # => [nil, 0]
```

My feeling was, both cases should return `[nil, 0]`.




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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:98487] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc`.
  2020-05-23  2:15 [ruby-core:98486] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc` samuel
@ 2020-05-23  2:26 ` merch-redmine
  2020-05-23  2:38 ` [ruby-core:98488] " samuel
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: merch-redmine @ 2020-05-23  2:26 UTC (permalink / raw)
  To: ruby-core

Issue #16908 has been updated by jeremyevans0 (Jeremy Evans).


While your particular example is non-intuitive, there is a simple explanation for it. The first time `hash.shift` is called, `hash` is empty, so it returns the default value (`0`).  It gets the default value by calling the default_proc for `hash` with a `nil` key.  There is no better option since `hash.shift` isn't provided a key.  The second time `hash.shift` is called, the hash is not empty, so it returns the first entry as a key value pair.  I agree `Hash#shift` semantics with a default_proc are questionable, but I'm not sure if it could be improved.

I don't think we should change this behavior.  It is expected that `Hash.new.shift` should return nil, as should `Hash.new(nil).shift` and `Hash.new{}.shift`.

`hash.shift` is used in conditionals:

```ruby
hash = {a: 1, b: 2}
while (k,v = hash.shift)
  p [k, v]
end
```

If you change `Hash#shift` to return an array when the hash is empty, you've turned this into an infinite loop.

----------------------------------------
Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`.
https://bugs.ruby-lang.org/issues/16908#change-85763

* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I don't have any strong opinion about this, but I observed the following behaviour which I thought was confusing. Maybe it's okay, or maybe we should change it to be more consistent.

```
hash = Hash.new{|k,v| k[v] = 0}

hash.shift # => 0
hash.shift # => [nil, 0]
```

My feeling was, both cases should return `[nil, 0]`.




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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:98488] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc`.
  2020-05-23  2:15 [ruby-core:98486] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc` samuel
  2020-05-23  2:26 ` [ruby-core:98487] " merch-redmine
@ 2020-05-23  2:38 ` samuel
  2020-05-23  2:53 ` [ruby-core:98489] " merch-redmine
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: samuel @ 2020-05-23  2:38 UTC (permalink / raw)
  To: ruby-core

Issue #16908 has been updated by ioquatix (Samuel Williams).


@jeremyevans0 I agree with your assessment, however that hash does not have default_proc so I assume that it would return `nil` after all key-value pairs are `shift`ed out. That's different from invoking `default_proc` and returning `[nil, 0]`.

----------------------------------------
Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`.
https://bugs.ruby-lang.org/issues/16908#change-85764

* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I don't have any strong opinion about this, but I observed the following behaviour which I thought was confusing. Maybe it's okay, or maybe we should change it to be more consistent.

```
hash = Hash.new{|k,v| k[v] = 0}

hash.shift # => 0
hash.shift # => [nil, 0]
```

My feeling was, both cases should return `[nil, 0]`.




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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:98489] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc`.
  2020-05-23  2:15 [ruby-core:98486] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc` samuel
  2020-05-23  2:26 ` [ruby-core:98487] " merch-redmine
  2020-05-23  2:38 ` [ruby-core:98488] " samuel
@ 2020-05-23  2:53 ` merch-redmine
  2020-05-23 12:37 ` [ruby-core:98491] " eregontp
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: merch-redmine @ 2020-05-23  2:53 UTC (permalink / raw)
  To: ruby-core

Issue #16908 has been updated by jeremyevans0 (Jeremy Evans).


ioquatix (Samuel Williams) wrote in #note-2:
> @jeremyevans0 I agree with your assessment, however that hash does not have default_proc so I assume that it would return `nil` after all key-value pairs are `shift`ed out. That's different from invoking `default_proc` and returning `[nil, 0]`.

Same principle applies when using a default_proc:

```ruby
# simple hash with indifferent access
hash = Hash.new{|h,k| h[k.to_s] unless k.is_a? String}
hash['a'] = 1
hash['b'] = 2
while (k,v = hash.shift)
  p [k, v]
end
```

----------------------------------------
Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`.
https://bugs.ruby-lang.org/issues/16908#change-85765

* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I don't have any strong opinion about this, but I observed the following behaviour which I thought was confusing. Maybe it's okay, or maybe we should change it to be more consistent.

```
hash = Hash.new{|k,v| k[v] = 0}

hash.shift # => 0
hash.shift # => [nil, 0]
```

My feeling was, both cases should return `[nil, 0]`.




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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:98491] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc`.
  2020-05-23  2:15 [ruby-core:98486] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc` samuel
                   ` (2 preceding siblings ...)
  2020-05-23  2:53 ` [ruby-core:98489] " merch-redmine
@ 2020-05-23 12:37 ` eregontp
  2020-05-23 12:39 ` [ruby-core:98492] " eregontp
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: eregontp @ 2020-05-23 12:37 UTC (permalink / raw)
  To: ruby-core

Issue #16908 has been updated by Eregon (Benoit Daloze).


Maybe `Hash#shift` should not call the `default_proc` or use `Hash#default`?
I.e., it would always return `nil` if `Hash#empty?`.
I think that would be more intuitive and probably compatible enough.

----------------------------------------
Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`.
https://bugs.ruby-lang.org/issues/16908#change-85767

* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I don't have any strong opinion about this, but I observed the following behaviour which I thought was confusing. Maybe it's okay, or maybe we should change it to be more consistent.

```
hash = Hash.new{|k,v| k[v] = 0}

hash.shift # => 0
hash.shift # => [nil, 0]
```

My feeling was, both cases should return `[nil, 0]`.




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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:98492] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc`.
  2020-05-23  2:15 [ruby-core:98486] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc` samuel
                   ` (3 preceding siblings ...)
  2020-05-23 12:37 ` [ruby-core:98491] " eregontp
@ 2020-05-23 12:39 ` eregontp
  2020-05-24  0:53 ` [ruby-core:98493] " daniel
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: eregontp @ 2020-05-23 12:39 UTC (permalink / raw)
  To: ruby-core

Issue #16908 has been updated by Eregon (Benoit Daloze).


In other words, the current semantics of `return hash.default(nil) if hash.empty?` feel hacky and actually harmful to me.
The user probably never expects to have the default_proc called with a `nil` key in many cases.

----------------------------------------
Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`.
https://bugs.ruby-lang.org/issues/16908#change-85768

* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I don't have any strong opinion about this, but I observed the following behaviour which I thought was confusing. Maybe it's okay, or maybe we should change it to be more consistent.

```
hash = Hash.new{|k,v| k[v] = 0}

hash.shift # => 0
hash.shift # => [nil, 0]
```

My feeling was, both cases should return `[nil, 0]`.




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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:98493] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc`.
  2020-05-23  2:15 [ruby-core:98486] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc` samuel
                   ` (4 preceding siblings ...)
  2020-05-23 12:39 ` [ruby-core:98492] " eregontp
@ 2020-05-24  0:53 ` daniel
  2021-03-17  5:31 ` [ruby-core:102900] " matz
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: daniel @ 2020-05-24  0:53 UTC (permalink / raw)
  To: ruby-core

Issue #16908 has been updated by Dan0042 (Daniel DeLorme).


I would expect Hash#shift to return either a key-value tuple or nil. Returning the default value is, honestly, incomprehensible.

----------------------------------------
Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`.
https://bugs.ruby-lang.org/issues/16908#change-85770

* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I don't have any strong opinion about this, but I observed the following behaviour which I thought was confusing. Maybe it's okay, or maybe we should change it to be more consistent.

```
hash = Hash.new{|k,v| k[v] = 0}

hash.shift # => 0
hash.shift # => [nil, 0]
```

My feeling was, both cases should return `[nil, 0]`.




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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:102900] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc`.
  2020-05-23  2:15 [ruby-core:98486] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc` samuel
                   ` (5 preceding siblings ...)
  2020-05-24  0:53 ` [ruby-core:98493] " daniel
@ 2021-03-17  5:31 ` matz
  2021-09-27  5:37 ` [ruby-core:105439] " ioquatix (Samuel Williams)
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: matz @ 2021-03-17  5:31 UTC (permalink / raw)
  To: ruby-core

Issue #16908 has been updated by matz (Yukihiro Matsumoto).


I don't remember why I made this behavior. Now I think `#shift` should return `nil` for an empty hash, without calling its default value, in the long run. @naruse claims the change should be postponed to `3.2` or later if we make the change.

Matz.

----------------------------------------
Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`.
https://bugs.ruby-lang.org/issues/16908#change-90961

* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I don't have any strong opinion about this, but I observed the following behaviour which I thought was confusing. Maybe it's okay, or maybe we should change it to be more consistent.

```
hash = Hash.new{|k,v| k[v] = 0}

hash.shift # => 0
hash.shift # => [nil, 0]
```

My feeling was, both cases should return `[nil, 0]`.




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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:105439] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc`.
  2020-05-23  2:15 [ruby-core:98486] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc` samuel
                   ` (6 preceding siblings ...)
  2021-03-17  5:31 ` [ruby-core:102900] " matz
@ 2021-09-27  5:37 ` ioquatix (Samuel Williams)
  2021-12-03  2:23 ` [ruby-core:106430] " naruse (Yui NARUSE)
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: ioquatix (Samuel Williams) @ 2021-09-27  5:37 UTC (permalink / raw)
  To: ruby-core

Issue #16908 has been updated by ioquatix (Samuel Williams).


Should we introduce some kind of deprecation or warning in 3.1?

----------------------------------------
Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`.
https://bugs.ruby-lang.org/issues/16908#change-93886

* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I don't have any strong opinion about this, but I observed the following behaviour which I thought was confusing. Maybe it's okay, or maybe we should change it to be more consistent.

```
hash = Hash.new{|k,v| k[v] = 0}

hash.shift # => 0
hash.shift # => [nil, 0]
```

My feeling was, both cases should return `[nil, 0]`.




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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:106430] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc`.
  2020-05-23  2:15 [ruby-core:98486] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc` samuel
                   ` (7 preceding siblings ...)
  2021-09-27  5:37 ` [ruby-core:105439] " ioquatix (Samuel Williams)
@ 2021-12-03  2:23 ` naruse (Yui NARUSE)
  2021-12-27 22:46 ` [ruby-core:106855] " jeremyevans0 (Jeremy Evans)
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: naruse (Yui NARUSE) @ 2021-12-03  2:23 UTC (permalink / raw)
  To: ruby-core

Issue #16908 has been updated by naruse (Yui NARUSE).


ioquatix (Samuel Williams) wrote in #note-8:
> Should we introduce some kind of deprecation or warning in 3.1?

Not allowed.
Ruby 3.1 shouldn't introduce anything which requests application developers to change something in their application code.
Deprecation warning is just a way of communications to request application developers to fix their application code.

----------------------------------------
Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`.
https://bugs.ruby-lang.org/issues/16908#change-95072

* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I don't have any strong opinion about this, but I observed the following behaviour which I thought was confusing. Maybe it's okay, or maybe we should change it to be more consistent.

```
hash = Hash.new{|k,v| k[v] = 0}

hash.shift # => 0
hash.shift # => [nil, 0]
```

My feeling was, both cases should return `[nil, 0]`.




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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:106855] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc`.
  2020-05-23  2:15 [ruby-core:98486] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc` samuel
                   ` (8 preceding siblings ...)
  2021-12-03  2:23 ` [ruby-core:106430] " naruse (Yui NARUSE)
@ 2021-12-27 22:46 ` jeremyevans0 (Jeremy Evans)
  2022-01-01  7:12 ` [ruby-core:106938] " ioquatix (Samuel Williams)
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2021-12-27 22:46 UTC (permalink / raw)
  To: ruby-core

Issue #16908 has been updated by jeremyevans0 (Jeremy Evans).


I've submitted a pull request to make `Hash#shift` return `nil` if the hash is empty: https://github.com/ruby/ruby/pull/5360

Not sure if we want that behavior in 3.2, or if we want to issue a deprecation warning in 3.2 and change in 3.3.  Considering there would be no way to avoid the deprecation warning if the hash has a default value, I think it's best to just change the behavior without deprecation.

----------------------------------------
Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`.
https://bugs.ruby-lang.org/issues/16908#change-95665

* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I don't have any strong opinion about this, but I observed the following behaviour which I thought was confusing. Maybe it's okay, or maybe we should change it to be more consistent.

```
hash = Hash.new{|k,v| k[v] = 0}

hash.shift # => 0
hash.shift # => [nil, 0]
```

My feeling was, both cases should return `[nil, 0]`.




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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:106938] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc`.
  2020-05-23  2:15 [ruby-core:98486] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc` samuel
                   ` (9 preceding siblings ...)
  2021-12-27 22:46 ` [ruby-core:106855] " jeremyevans0 (Jeremy Evans)
@ 2022-01-01  7:12 ` ioquatix (Samuel Williams)
  2022-01-14  3:01 ` [ruby-core:107113] " mame (Yusuke Endoh)
  2022-01-15  1:39 ` [ruby-core:107135] " ioquatix (Samuel Williams)
  12 siblings, 0 replies; 14+ messages in thread
From: ioquatix (Samuel Williams) @ 2022-01-01  7:12 UTC (permalink / raw)
  To: ruby-core

Issue #16908 has been updated by ioquatix (Samuel Williams).


Pretty much anything will be better than the current behaviour. I think your proposal makes sense.

----------------------------------------
Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`.
https://bugs.ruby-lang.org/issues/16908#change-95761

* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I don't have any strong opinion about this, but I observed the following behaviour which I thought was confusing. Maybe it's okay, or maybe we should change it to be more consistent.

```
hash = Hash.new{|k,v| k[v] = 0}

hash.shift # => 0
hash.shift # => [nil, 0]
```

My feeling was, both cases should return `[nil, 0]`.




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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:107113] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc`.
  2020-05-23  2:15 [ruby-core:98486] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc` samuel
                   ` (10 preceding siblings ...)
  2022-01-01  7:12 ` [ruby-core:106938] " ioquatix (Samuel Williams)
@ 2022-01-14  3:01 ` mame (Yusuke Endoh)
  2022-01-15  1:39 ` [ruby-core:107135] " ioquatix (Samuel Williams)
  12 siblings, 0 replies; 14+ messages in thread
From: mame (Yusuke Endoh) @ 2022-01-14  3:01 UTC (permalink / raw)
  To: ruby-core

Issue #16908 has been updated by mame (Yusuke Endoh).

Assignee set to jeremyevans0 (Jeremy Evans)
Status changed from Open to Assigned

Jeremy's approach (make Hash#shift return nil if the hash is empty) was approved by @matz.

----------------------------------------
Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`.
https://bugs.ruby-lang.org/issues/16908#change-95959

* Author: ioquatix (Samuel Williams)
* Status: Assigned
* Priority: Normal
* Assignee: jeremyevans0 (Jeremy Evans)
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I don't have any strong opinion about this, but I observed the following behaviour which I thought was confusing. Maybe it's okay, or maybe we should change it to be more consistent.

```
hash = Hash.new{|k,v| k[v] = 0}

hash.shift # => 0
hash.shift # => [nil, 0]
```

My feeling was, both cases should return `[nil, 0]`.




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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:107135] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc`.
  2020-05-23  2:15 [ruby-core:98486] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc` samuel
                   ` (11 preceding siblings ...)
  2022-01-14  3:01 ` [ruby-core:107113] " mame (Yusuke Endoh)
@ 2022-01-15  1:39 ` ioquatix (Samuel Williams)
  12 siblings, 0 replies; 14+ messages in thread
From: ioquatix (Samuel Williams) @ 2022-01-15  1:39 UTC (permalink / raw)
  To: ruby-core

Issue #16908 has been updated by ioquatix (Samuel Williams).


Thank you @jeremyevans

----------------------------------------
Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`.
https://bugs.ruby-lang.org/issues/16908#change-95982

* Author: ioquatix (Samuel Williams)
* Status: Closed
* Priority: Normal
* Assignee: jeremyevans0 (Jeremy Evans)
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I don't have any strong opinion about this, but I observed the following behaviour which I thought was confusing. Maybe it's okay, or maybe we should change it to be more consistent.

```
hash = Hash.new{|k,v| k[v] = 0}

hash.shift # => 0
hash.shift # => [nil, 0]
```

My feeling was, both cases should return `[nil, 0]`.




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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-01-15  1:39 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-23  2:15 [ruby-core:98486] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc` samuel
2020-05-23  2:26 ` [ruby-core:98487] " merch-redmine
2020-05-23  2:38 ` [ruby-core:98488] " samuel
2020-05-23  2:53 ` [ruby-core:98489] " merch-redmine
2020-05-23 12:37 ` [ruby-core:98491] " eregontp
2020-05-23 12:39 ` [ruby-core:98492] " eregontp
2020-05-24  0:53 ` [ruby-core:98493] " daniel
2021-03-17  5:31 ` [ruby-core:102900] " matz
2021-09-27  5:37 ` [ruby-core:105439] " ioquatix (Samuel Williams)
2021-12-03  2:23 ` [ruby-core:106430] " naruse (Yui NARUSE)
2021-12-27 22:46 ` [ruby-core:106855] " jeremyevans0 (Jeremy Evans)
2022-01-01  7:12 ` [ruby-core:106938] " ioquatix (Samuel Williams)
2022-01-14  3:01 ` [ruby-core:107113] " mame (Yusuke Endoh)
2022-01-15  1:39 ` [ruby-core:107135] " ioquatix (Samuel Williams)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).