[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

is /#$/ a Ruby bug ?

Dan Kohn

1/3/2006 2:40:00 AM

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?

1 Answer

Marcel Molina Jr.

1/3/2006 2:46:00 AM

0

On Tue, Jan 03, 2006 at 11:42:57AM +0900, Dan Kohn wrote:
> 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:

>> $global = 'hello'
=> "hello"
>> "the var value is #$global"
=> "the var value is hello"
>> $/ = 'oops, gotcha'
=> "oops, gotcha"
>> "the var value is #$/"
=> "the var value is oops, gotcha"

marcel
--
Marcel Molina Jr. <marcel@vernix.org>