diff --git a/object.c b/object.c index b987e13ae8..49729f644f 100644 --- a/object.c +++ b/object.c @@ -2264,17 +2264,21 @@ id_for_attr(VALUE obj, VALUE name) * value of each instance variable. Equivalent to calling * ``attr:name'' on each name in turn. * String arguments are converted to symbols. + * Returns an array of defined methods names as symbols. */ static VALUE rb_mod_attr_reader(int argc, VALUE *argv, VALUE klass) { int i; + VALUE names = rb_ary_new2(argc); for (i=0; iattr_accessor(name) but deprecated. * The last form is equivalent to attr_reader(name) but deprecated. + * Returns an array of defined methods names as symbols. *-- * \private * \todo can be static? @@ -2295,9 +2300,14 @@ VALUE rb_mod_attr(int argc, VALUE *argv, VALUE klass) { if (argc == 2 && (argv[1] == Qtrue || argv[1] == Qfalse)) { - rb_category_warning(RB_WARN_CATEGORY_DEPRECATED, "optional boolean argument is obsoleted"); - rb_attr(klass, id_for_attr(klass, argv[0]), 1, RTEST(argv[1]), TRUE); - return Qnil; + ID id = id_for_attr(klass, argv[0]); + VALUE names = rb_ary_new(); + + rb_category_warning(RB_WARN_CATEGORY_DEPRECATED, "optional boolean argument is obsoleted"); + rb_attr(klass, id, 1, RTEST(argv[1]), TRUE); + rb_ary_push(names, ID2SYM(id)); + if (argv[1] == Qtrue) rb_ary_push(names, rb_str_intern(rb_sprintf("%"PRIsVALUE"=", ID2SYM(id)))); + return names; } return rb_mod_attr_reader(argc, argv, klass); } @@ -2310,17 +2320,21 @@ rb_mod_attr(int argc, VALUE *argv, VALUE klass) * Creates an accessor method to allow assignment to the attribute * symbol.id2name. * String arguments are converted to symbols. + * Returns an array of defined methods names as symbols. */ static VALUE rb_mod_attr_writer(int argc, VALUE *argv, VALUE klass) { int i; + VALUE names = rb_ary_new2(argc); for (i=0; i