diff options
author | Jeremy Evans <code@jeremyevans.net> | 2020-09-03 08:00:10 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2020-09-28 08:38:06 -0700 |
commit | 346301e2329c46362a6089311d0a64b8734b35ec (patch) | |
tree | 4b74d3d91bc7cf52cc4e1f50f8d62c3918aff26c /warning.rb | |
parent | 92c3ad9c276d048bf6fba1145ffccf8678fe8af1 (diff) | |
download | ruby-346301e2329c46362a6089311d0a64b8734b35ec.tar.gz |
Add rb_category_warn{,ing} for warning messages with categories
This adds the following C-API functions that can be used to emit
warnings with categories included:
```c
void rb_category_warn(const char *, const char*, ...)
void rb_category_warning(const char*, const char*, ...)
```
Internally in error.c, there is an rb_warn_category function
that will call Warning.warn with the string and the category
keyword if it doesn't have an arity of 1, and will call
Warning.warn with just the string if it has an arity of 1.
This refactors the rb_warn_deprecated{,_to_remove} functions
to use rb_warn_category.
This makes Kernel#warn accept a category keyword and pass it
to Warning.warn, so that Ruby methods can more easily emit
warnings with categories. rb_warn_category makes sure that
the passed category is a already defined category symbol
before calling Warning.warn.
The only currently defined warning category is :deprecated,
since that is what is already used. More categories can be
added in later commits.
Diffstat (limited to 'warning.rb')
-rw-r--r-- | warning.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/warning.rb b/warning.rb index f81ad77629..22acd3424e 100644 --- a/warning.rb +++ b/warning.rb @@ -39,7 +39,7 @@ module Kernel # # baz.rb:6: warning: invalid call to foo # - def warn(*msgs, uplevel: nil) - Primitive.rb_warn_m(msgs, uplevel) + def warn(*msgs, uplevel: nil, category: nil) + Primitive.rb_warn_m(msgs, uplevel, category) end end |