Skip to content

Commit

Permalink
Fix Hash.shift (3.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Mar 7, 2023
1 parent 65e68aa commit 2527974
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ itself, JRuby and Rubinius.

- `Enumerator.product` and `Enumerator::Product`

#### Hash

- `shift` (with correct behavior when empty)

## Ruby 3.1 backports

#### Array
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ IGNORE = %w[
3.1.0/enumerable/compact
3.1.0/struct/keyword_init
3.2.0/enumerator/product
3.2.0/hash/shift
]

CLASS_MAP = Hash.new{|k, v| k[v] = v}.merge!(
Expand Down
3 changes: 3 additions & 0 deletions lib/backports/3.2.0/hash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'backports/tools/require_relative_dir'

Backports.require_relative_dir
10 changes: 10 additions & 0 deletions lib/backports/3.2.0/hash/shift.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if Hash.new(42).shift
require 'backports/tools/alias_method_chain'

class Hash
def shift_with_correct_behaviour_when_empty
shift_without_correct_behaviour_when_empty unless empty?
end
Backports.alias_method_chain self, :shift, :correct_behaviour_when_empty
end
end

0 comments on commit 2527974

Please sign in to comment.