End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Module#attr
attr(name, ...) → array
attr(name, true) → array
attr(name, false) → array
object.c
View on GitHub ↗
VALUE
rb_mod_attr(int argc, VALUE *argv, VALUE klass)
{
if (argc == 2 && (argv[1] == Qtrue || argv[1] == Qfalse)) {
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, ID2SYM(rb_id_attrset(id)));
return names;
}
return rb_mod_attr_reader(argc, argv, klass);
}
The first form is equivalent to attr_reader. The second form is equivalent to attr_accessor(name) but deprecated. The last form is equivalent to attr_reader(name) but deprecated. Returns an array of defined method names as symbols.
Ruby version changes
-
3.0
-
Module#attr_accessor,Module#attr_reader,Module#attr_writerandModule#attrmethods now return an array of defined method names as symbols. [Feature #17314]
-
See also
#append_features
#attr_accessor
#ancestors
#attr_reader
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0