Skip to content

Commit 36518f3

Browse files
committed
Fix Symbol#match
PullRequest: truffleruby/916
2 parents c324c94 + 9a038dd commit 36518f3

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Bug fixes:
99
* Fixed `Addrinfo.new(String)` to reliably find the address family (#1702).
1010
* Fixed argument checks in `BasicSocket#setsockopt` (#1460).
1111
* Fixed `ObjectSpace.trace_object_allocations` (#1456).
12+
* Fixed the `Symbol#match` returning `MatchData` (#1706).
1213

1314
Compatibility:
1415

spec/tags/core/symbol/match_tags.txt

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

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,28 @@ def match(pattern)
9292
when Regexp
9393
match_data = pattern.search_region(str, 0, str.bytesize, true)
9494
Truffle::RegexpOperations.set_last_match(match_data, Truffle.invoke_primitive(:caller_binding))
95-
return match_data.byte_begin(0) if match_data
95+
match_data
9696
when String
9797
raise TypeError, 'type mismatch: String given'
9898
else
9999
pattern =~ str
100100
end
101101
end
102102

103-
alias_method :=~, :match
103+
def =~(pattern)
104+
str = to_s
105+
106+
case pattern
107+
when Regexp
108+
match_data = pattern.search_region(str, 0, str.bytesize, true)
109+
Truffle::RegexpOperations.set_last_match(match_data, Truffle.invoke_primitive(:caller_binding))
110+
match_data.byte_begin(0) if match_data
111+
when String
112+
raise TypeError, 'type mismatch: String given'
113+
else
114+
pattern =~ str
115+
end
116+
end
104117

105118
def match?(pattern, pos=0)
106119
pattern = Truffle::Type.coerce_to_regexp(pattern) unless pattern.kind_of? Regexp

0 commit comments

Comments
 (0)