const_get(p1, p2 = v2)
public
Checks for a constant with the given name
in mod If inherit is set, the lookup will also search the
ancestors (and Object if mod is a Module.)
The value of the constant is returned if a definition is found, otherwise a
NameError is raised.
Math.const_get(:PI)
Show source
static VALUE
rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
{
VALUE name, recur;
ID id;
if (argc == 1) {
name = argv[0];
recur = Qtrue;
}
else {
rb_scan_args(argc, argv, "11", &name, &recur);
}
id = rb_to_id(name);
if (!rb_is_const_id(id)) {
rb_name_error(id, "wrong constant name %s", rb_id2name(id));
}
return RTEST(recur) ? rb_const_get(mod, id) : rb_const_get_at(mod, id);
}