mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[Feature #20293] Add Warning.categories
This commit is contained in:
parent
f36a71e269
commit
1ad366134d
3 changed files with 26 additions and 2 deletions
21
error.c
21
error.c
|
@ -252,6 +252,26 @@ rb_warning_s_aset(VALUE mod, VALUE category, VALUE flag)
|
|||
return flag;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* categories -> array
|
||||
*
|
||||
* Returns a list of the supported category symbols.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
rb_warning_s_categories(VALUE mod)
|
||||
{
|
||||
st_index_t num = warning_categories.id2enum->num_entries;
|
||||
ID *ids = ALLOCA_N(ID, num);
|
||||
num = st_keys(warning_categories.id2enum, ids, num);
|
||||
VALUE ary = rb_ary_new_capa(num);
|
||||
for (st_index_t i = 0; i < num; ++i) {
|
||||
rb_ary_push(ary, ID2SYM(ids[i]));
|
||||
}
|
||||
return rb_ary_freeze(ary);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* warn(msg, category: nil) -> nil
|
||||
|
@ -3413,6 +3433,7 @@ Init_Exception(void)
|
|||
rb_mWarning = rb_define_module("Warning");
|
||||
rb_define_singleton_method(rb_mWarning, "[]", rb_warning_s_aref, 1);
|
||||
rb_define_singleton_method(rb_mWarning, "[]=", rb_warning_s_aset, 2);
|
||||
rb_define_singleton_method(rb_mWarning, "categories", rb_warning_s_categories, 0);
|
||||
rb_define_method(rb_mWarning, "warn", rb_warning_s_warn, -1);
|
||||
rb_extend_object(rb_mWarning, rb_mWarning);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue