is /#$/ a Ruby bug ?

D

Dan Kohn

p /#$/.match("#")[0] # syntax error: unterminated string meets eof

The interpreter seems to interpret the first # as a comment but not the
second.

p /\#$/.match("#")[0] # this works

This seems even odder:

p /[#$]/.match("#")[0] # syntax error: compile error

p /[#\$]/.match("#")[0] # we can escape the $ rather than the #

Shouldn't the interpreter ignore # within a Regexp /.../ unless there's
an x flag, a #{...} substitution, or a (?#...) comment? Bug or feature?
 
M

Marcel Molina Jr.

p /#$/.match("#")[0] # syntax error: unterminated string meets eof

The interpreter seems to interpret the first # as a comment but not the
second.

p /\#$/.match("#")[0] # this works

This seems even odder:

p /[#$]/.match("#")[0] # syntax error: compile error

p /[#\$]/.match("#")[0] # we can escape the $ rather than the #

Shouldn't the interpreter ignore # within a Regexp /.../ unless there's
an x flag, a #{...} substitution, or a (?#...) comment? Bug or feature?

String interpolation with #{} need not use the enclosing curly brackets when
interpolating instance variables or global variables:
=> "the var value is oops, gotcha"

marcel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top