Skip to content

Commit 5cdbda2

Browse files
committed
Implement MatchData#deconstruct_keys
1 parent 7bb1619 commit 5cdbda2

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

spec/tags/core/matchdata/deconstruct_keys_tags.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/main/ruby/truffleruby/core/match_data.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ def captures
6868
end
6969
alias_method :deconstruct, :captures
7070

71+
def deconstruct_keys(array_of_names)
72+
Truffle::Type.rb_check_type(array_of_names, Array) unless Primitive.nil?(array_of_names)
73+
74+
hash = named_captures.transform_keys(&:to_sym)
75+
return hash if Primitive.nil?(array_of_names)
76+
77+
ret = {}
78+
return ret if array_of_names.size > hash.size
79+
80+
array_of_names.each do |key|
81+
Truffle::Type.rb_check_type(key, Symbol)
82+
break unless hash.key?(key)
83+
ret[key] = hash[key]
84+
end
85+
86+
ret
87+
end
88+
7189
def names
7290
regexp.names
7391
end

test/mri/excludes/TestRegexp.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
exclude :test_initialize_option, "<//m> expected but was"
4141
exclude :test_initialize_bool_warning, "expected: /expected true or false as ignorecase/"
4242
exclude :test_linear_time_p, "NoMethodError: undefined method `linear_time?' for Regexp:Class"
43-
exclude :test_match_data_deconstruct_keys, "NoMethodError: undefined method `deconstruct_keys' for #<MatchData \"foobarbaz\">"
4443
exclude :test_extended_comment_invalid_escape_bug_18294, "assert_separately failed with error message"
4544
exclude :test_timeout_nil, "NoMethodError: undefined method `timeout=' for Regexp:Class"
4645
exclude :test_timeout_shorter_than_global, "NoMethodError: undefined method `timeout=' for Regexp:Class"

0 commit comments

Comments
 (0)