Skip to content

Commit 2b1b37a

Browse files
committed
Fix setting $~ for Enumerator::Lazy#grep_v
1 parent 054d6af commit 2b1b37a

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

spec/tags/core/enumerator/lazy/grep_v_tags.txt

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

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -408,20 +408,18 @@ def grep(pattern, &block)
408408
end
409409
end
410410

411-
def grep_v(pattern)
412-
if block_given?
413-
Lazy.new(self, nil) do |yielder, *args|
414-
val = args.length >= 2 ? args : args.first
415-
unless pattern === val
416-
# Regexp.set_block_last_match # TODO BJF Aug 2, 2016 Investigate for removal
411+
def grep_v(pattern, &block)
412+
binding = block ? block.binding : Truffle.invoke_primitive(:caller_binding)
413+
414+
Lazy.new(self, nil) do |yielder, *args|
415+
val = args.length >= 2 ? args : args.first
416+
matches = pattern === val
417+
Truffle::RegexpOperations.set_last_match($~, binding)
418+
419+
unless matches
420+
if block
417421
yielder.yield yield(val)
418-
end
419-
end
420-
else
421-
Lazy.new(self, nil) do |yielder, *args|
422-
val = args.length >= 2 ? args : args.first
423-
unless pattern === val
424-
# Regexp.set_block_last_match # TODO BJF Aug 2, 2016 Investigate for removal
422+
else
425423
yielder.yield val
426424
end
427425
end

0 commit comments

Comments
 (0)