[ruby-talk:02417] String expansion of class variables

From: Dave Thomas <Dave@...>
Date: 2000-04-10 03:56:40 UTC
List: ruby-talk #2417
You can expand global and instance variables in strings without the
braces:

 "instance #@inst, global #$global"

However, you cannot expand class variables:

  "class #@@cls"

==>

  -:1: compile error in string expansion (SyntaxError)

The attached patch seems fairly benign.


Dave



Index: ChangeLog
===================================================================
RCS file: /home/cvs/ruby/ChangeLog,v
retrieving revision 1.53
diff -u -r1.53 ChangeLog
--- ChangeLog   2000/03/23 08:37:23     1.53
+++ ChangeLog   2000/04/10 03:53:30
@@ -1,3 +1,7 @@
+Sun Apr  9 20:49:19 2000  Dave Thomas  <Dave@Thomases.com>
+
+       * parse.y (str_extend): Allow class variables to be expanded
+
 Thu Mar 23 02:26:14 2000  Yukihiro Matsumoto  <matz@netlab.co.jp>
        * io.c (rb_io_fptr_finalize): fptr may be null.
Index: parse.y
===================================================================
RCS file: /home/cvs/ruby/parse.y,v
retrieving revision 1.24
diff -u -r1.24 parse.y
--- parse.y     2000/03/23 08:37:29     1.24
+++ parse.y     2000/04/10 03:53:31
@@ -3549,6 +3549,10 @@
       case '@':
        tokadd(c);
        c = nextc();
+        if (c == '@') {
+          tokadd(c);
+          c = nextc();
+        }
        while (is_identchar(c)) {
            tokadd(c);
            if (ismbchar(c)) {

In This Thread

Prev Next