Regexes can have interpolated values just like strings
When an expression is a single name and that name starts
with a special symbol like @, @@, or $, the braces can
be omitted
$/ is one of the ugly special variables
So #$/ is interpreted as inserting the value of $/ into
the regex
The regex then consumes the rest of the line
The interpreter apparently does not distinguish between
strings and regular expressions when reporting that
something is unterminated.
I’m not sure I followed that. Can you explain to me how 1-6 explain
this?:
p “#$”
SyntaxError: compile error
(irb):22: unterminated string meets end of file
from (irb):22
···
–
Daniel Carrera, Math PhD student at UMD. PGP KeyID: 9AF77A88
.-“~~~”-.
/ O O \ ATTENTION ALL PASCAL USERS:
: s :
\ _/ / To commemorate the anniversary of Blaise Pascal’s
`-._.-’ birth (today) all your programs will run at half speed.
Wow, I’d’ve never gotten that one, and I’m usually pretty good at
catching stuff like that.
I don’t think I’d call it a bug, but to my eyes, #2 seems like a
design “whodathunkit”. Mind you, I’m really quite against poetry
mode and a lot of other seemingly “magic” things the interpreter does
(if I want interpolation in a string, I’ll tell it so, in this case).
SyntaxError: compile error
(irb):22: unterminated string meets end of file
from (irb):22
Isn’t $" also a special variable?
Okay, I would suggest the following behaviour would make most sense:
p “#$” => ‘#$’
p “#{$”}" => contents of $"
Thoughts?
···
–
Daniel Carrera, Math PhD student at UMD. PGP KeyID: 9AF77A88
.-“~~~”-.
/ O O \ ATTENTION ALL PASCAL USERS:
: s :
\ _/ / To commemorate the anniversary of Blaise Pascal’s
`-._.-’ birth (today) all your programs will run at half speed.
SyntaxError: compile error
(irb):22: unterminated string meets end of file
from (irb):22
Isn’t $" also a special variable?
Okay, I would suggest the following behaviour would make most sense:
p “#$” => ‘#$’
p “#{$”}" => contents of $"
Thoughts?
I’d rather just see the ugly variables go away. The Ruby Way intentionally avoided their use. There are a few
in there, but most are in code contributed by others.
Rather than change the parser, I’d suggest that the nuby should
be aware that #$ will interpolate a global variable if the rest
of the variable name is valid.
I’ve been playing in irb and this is making my head hurt.
Personally I’d say: If you want a literal #$, then either escape
the $ or use a non-interpolating string.
I think you may have a free subscription to safari.oreilly.com for 14
days and get an electronic copy from there. You may need to pay after
that time, anyway…
···
il Sat, 30 Aug 2003 11:53:58 +0200, Rene van Bevern rvb@rvb.dyndns.org ha scritto::
can “The Ruby Way” be found online, like the pickaxe? (although i have
the pickaxe in “bookform”).
I’ve heard that safari.net has it – downloadable
for a fee of some kind.
downloading for a fee? … no thanks, then i will just buy your book on
paper ;> … i prefer paperbooks, although they are not grep-able
i have just read the sample pages … looks good