From: nobu.nokada@... Date: 2003-06-01T08:58:15+09:00 Subject: Re: [RCR] attr_reader :foo? Hi, At Sun, 1 Jun 2003 08:04:16 +0900, Joel VanderWerf wrote: > Since the use of attr_accessor construct is so pointless in this case, > why not change the semantics: > > "attr_reader :foo?" defines a method #foo? which gets > the value of @foo, > > "attr_writer :foo?" defines a method #foo= which sets > the value of @foo. Like this? Index: eval.c =================================================================== RCS file: /cvs/ruby/src/ruby/eval.c,v retrieving revision 1.449 diff -u -2 -p -r1.449 eval.c --- eval.c 30 May 2003 16:07:25 -0000 1.449 +++ eval.c 31 May 2003 23:54:00 -0000 @@ -539,4 +539,5 @@ rb_attr(klass, id, read, write, ex) ID attriv; int noex; + int len; if (!ex) noex = NOEX_PUBLIC; @@ -557,9 +558,13 @@ rb_attr(klass, id, read, write, ex) name = rb_id2name(id); - if (!name) { + if (!name || !*name) { rb_raise(rb_eArgError, "argument needs to be symbol or string"); } - buf = ALLOCA_N(char,strlen(name)+2); - sprintf(buf, "@%s", name); + len = strlen(name) - 1; + if (name[len] != '!' && name[len] != '?') len++; + buf = ALLOCA_N(char, len+2); + buf[0] = '@'; + memcpy(buf+1, name, len); + buf[len+1] = '\0'; attriv = rb_intern(buf); if (read) { @@ -568,5 +573,6 @@ rb_attr(klass, id, read, write, ex) } if (write) { - sprintf(buf, "%s=", name); + memcpy(buf, name, len); + strcpy(&buf[len], "="); id = rb_intern(buf); rb_add_method(klass, id, NEW_ATTRSET(attriv), noex); -- Nobu Nakada