Skip to content

Commit 3379c4b

Browse files
committed
Merge branch 'symbol_match' of https://github.com/zhublik/truffleruby into zhublik-symbol_match
2 parents c324c94 + 8bf743e commit 3379c4b

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

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)