* struct.c (make_struct): allow const_id for accessor names.

[ruby-core:04585]

* eval.c (rb_attr): check if attribute name is local_id or
  const_id.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2005-05-11 01:11:52 +00:00
parent 7efdc82d2e
commit 1843d8abbc
6 changed files with 18 additions and 7 deletions

View file

@ -5,6 +5,8 @@
*~ *~
.ccmalloc .ccmalloc
.ppack .ppack
.ext
.rbconfig.time
COPYING.LIB COPYING.LIB
ChangeLog.pre-alpha ChangeLog.pre-alpha
ChangeLog.pre1_1 ChangeLog.pre1_1

View file

@ -6016,6 +6016,14 @@ Thu Mar 18 21:44:38 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/drb.rb: backport drb.rb 1.16. * lib/drb/drb.rb: backport drb.rb 1.16.
Fri Mar 18 17:49:51 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* struct.c (make_struct): allow const_id for accessor names.
[ruby-core:04585]
* eval.c (rb_attr): check if attribute name is local_id or
const_id.
Thu Mar 18 16:22:38 2004 Yukihiro Matsumoto <matz@ruby-lang.org> Thu Mar 18 16:22:38 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (proc_eq): avoid false positive by using scope and * eval.c (proc_eq): avoid false positive by using scope and

7
eval.c
View file

@ -622,6 +622,9 @@ rb_attr(klass, id, read, write, ex)
} }
} }
if (!rb_is_local_id(id) && !rb_is_const_id(id)) {
rb_name_error(id, "invalid attribute name `%s'", rb_id2name(id));
}
name = rb_id2name(id); name = rb_id2name(id);
if (!name) { if (!name) {
rb_raise(rb_eArgError, "argument needs to be symbol or string"); rb_raise(rb_eArgError, "argument needs to be symbol or string");
@ -633,9 +636,7 @@ rb_attr(klass, id, read, write, ex)
rb_add_method(klass, id, NEW_IVAR(attriv), noex); rb_add_method(klass, id, NEW_IVAR(attriv), noex);
} }
if (write) { if (write) {
sprintf(buf, "%s=", name); rb_add_method(klass, rb_id_attrset(id), NEW_ATTRSET(attriv), noex);
id = rb_intern(buf);
rb_add_method(klass, id, NEW_ATTRSET(attriv), noex);
} }
} }

View file

@ -398,7 +398,7 @@ The variable ruby-indent-level controls the amount of indentation.
((and (not (eobp)) ((and (not (eobp))
(ruby-expr-beg 'expr-qstr) (ruby-expr-beg 'expr-qstr)
(not (looking-at "%=")) (not (looking-at "%="))
(looking-at "%[QqrxWw]?\\(.\\)")) (looking-at "%[QqrxWw]?\\([^a-zA-Z0-9 \t\n]\\)"))
(goto-char (match-beginning 1)) (goto-char (match-beginning 1))
(setq expand (not (memq (char-before) '(?q ?w)))) (setq expand (not (memq (char-before) '(?q ?w))))
(setq w (match-string 1)) (setq w (match-string 1))

View file

@ -2471,7 +2471,7 @@ VALUE ruby_top_self;
* Creating a new Name * Creating a new Name
* *
* Classes, modules, and objects are interrelated. In the diagram * Classes, modules, and objects are interrelated. In the diagram
* that follows, the arrows represent inheritance, and the * that follows, the vertical arrows represent inheritance, and the
* parentheses meta-classes. All metaclasses are instances * parentheses meta-classes. All metaclasses are instances
* of the class `Class'. * of the class `Class'.
* *

View file

@ -212,7 +212,7 @@ make_struct(name, members, klass)
rb_define_singleton_method(nstr, "members", rb_struct_s_members_m, 0); rb_define_singleton_method(nstr, "members", rb_struct_s_members_m, 0);
for (i=0; i< RARRAY(members)->len; i++) { for (i=0; i< RARRAY(members)->len; i++) {
ID id = SYM2ID(RARRAY(members)->ptr[i]); ID id = SYM2ID(RARRAY(members)->ptr[i]);
if (rb_is_local_id(id)) { if (rb_is_local_id(id) || rb_is_const_id(id)) {
if (i<10) { if (i<10) {
rb_define_method_id(nstr, id, ref_func[i], 0); rb_define_method_id(nstr, id, ref_func[i], 0);
} }
@ -488,7 +488,7 @@ inspect_struct(s)
} }
slot = RARRAY(members)->ptr[i]; slot = RARRAY(members)->ptr[i];
id = SYM2ID(slot); id = SYM2ID(slot);
if (rb_is_local_id(id)) { if (rb_is_local_id(id) || rb_is_const_id(id)) {
p = rb_id2name(id); p = rb_id2name(id);
rb_str_cat2(str, p); rb_str_cat2(str, p);
} }