Problem solved by geniuses on IRC: check final comment for complete log. The cause of this bug is unexpected to say the least!
This is the code that isn't working:
Assume the input is "Hello world @123"
def memo_content(input, remote: false)
content = sanitize input
content = content.gsub(/@([a-z0-9A-Z]+)/) do |match|
binding.pry
link_to "@#{ $1 }", memo_path($1), class: "marker", remote: remote
end
content = simple_format content, { }, sanitize: false
end
When it gets to the pry binding, I check what the "match" and "$1" are holding:
[1] pry> match
=> "@W"
[2] pry> $1
=> nil
[3] pry> content
=> "Hello world @123"
However, when I remove the second line:
def memo_content(input, remote: false)
content = input.gsub(/@([a-z0-9A-Z]+)/) do |match|
binding.pry
link_to "@#{ $1 }", memo_path($1), class: "marker", remote: remote
...
end
It works jusst fine, and "$1" holds "123" as it should.
What exactly is happening here? Why does it say "$1" is nill when clearly there was a match?
First run, working:
Second run: Failing. Pry inside block.