Method: Module#attr_reader

Defined in:
object.c

#attr_reader(symbol, ...) ⇒ Array #attr(symbol, ...) ⇒ Array #attr_reader(string, ...) ⇒ Array #attr(string, ...) ⇒ Array

Creates instance variables and corresponding methods that return the 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 method names as symbols.

Overloads:



2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
# File 'object.c', line 2317

static VALUE
rb_mod_attr_reader(int argc, VALUE *argv, VALUE klass)
{
    int i;
    VALUE names = rb_ary_new2(argc);

    for (i=0; i<argc; i++) {
        ID id = id_for_attr(klass, argv[i]);
        rb_attr(klass, id, TRUE, FALSE, TRUE);
        rb_ary_push(names, ID2SYM(id));
    }
    return names;
}