Skip to content

Commit ecf6158

Browse files
authored
Merge pull request #394 from viralpraxis/fix-regexp-with-global-variable-unparsing
Fix regexp with gvar unparsing
2 parents 43b38a5 + 5e67cf6 commit ecf6158

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

lib/unparser/node_helpers.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def n?(type, node)
4343
dstr
4444
empty_else
4545
ensure
46+
gvar
4647
hash
4748
hash_pattern
4849
if

lib/unparser/writer/regexp.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ def emit_body(node)
5555
write('#{')
5656
node.children.each(&method(:visit))
5757
write('}')
58+
elsif n_gvar?(node)
59+
write('#')
60+
write_regular(node.children.first.to_s)
5861
else
5962
write_regular(node.children.first)
6063
end

test/corpus/literal/regexp.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@
3030
/
3131
a
3232
/
33+
/aaa #{$bbb}/
34+
/aaa #$bbb/

0 commit comments

Comments
 (0)