Skip to content

Implement Hash#except #2463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/truffleruby.mspec
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class MSpecScript
# Use spec/ruby/core/nil/nil_spec.rb as a dummy file to avoid being empty
set :next, %w[
spec/ruby/core/nil/nil_spec.rb
spec/ruby/core/hash/except_spec.rb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this since RUBY_VERSION is 3.0.2 on master now, but no big deal I'll just have a commit on top to revert this small change.
Instead we want to jt untag spec/ruby/core/hash/except_spec.rb, I'll do that on top.

]

set :tags_patterns, [
Expand Down
9 changes: 9 additions & 0 deletions src/main/ruby/truffleruby/core/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@ def deconstruct_keys(keys)
self
end

def except(*keys)
new_hash = {}.replace(dup)
new_hash.default = nil
keys.each do |k|
new_hash.delete(k)
end
new_hash
end

def fetch(key, default=undefined)
value = Primitive.hash_get_or_undefined(self, key)
unless Primitive.undefined?(value)
Expand Down