Module: Warning
- Defined in:
- error.c,
error.c
Overview
The Warning module contains a single method named #warn, and the module extends itself, making Warning.warn available. Warning.warn is called for all warnings issued by Ruby. By default, warnings are printed to $stderr.
By overriding Warning.warn, you can change how warnings are handled by Ruby, either filtering some warnings, and/or outputting warnings somewhere other than $stderr. When Warning.warn is overridden, super can be called to get the default behavior of printing the warning to $stderr.
Defined Under Namespace
Classes: buffer
Class Method Summary collapse
-
.[](category) ⇒ Object
call-seq Warning -> true or false.
-
.[]=(category, flag) ⇒ Object
call-seq Warning = flag -> flag.
Instance Method Summary collapse
-
#warn(msg) ⇒ nil
Writes warning message
msg
to $stderr.
Class Method Details
.[](category) ⇒ Object
call-seq
Warning[category] -> true or false
Returns the flag to show the warning messages for category
. Supported categories are:
:deprecated
-
deprecation warnings
-
assignment of non-nil value to
$,
and$;
-
keyword arguments
-
proc/lambda without block
etc.
:experimental
-
experimental features
-
Pattern matching
199 200 201 202 203 204 205 206 |
# File 'error.c', line 199
static VALUE
rb_warning_s_aref(VALUE mod, VALUE category)
{
rb_warning_category_t cat = rb_warning_category_from_name(category);
if (rb_warning_category_enabled_p(cat))
return Qtrue;
return Qfalse;
}
|
.[]=(category, flag) ⇒ Object
call-seq
Warning[category] = flag -> flag
Sets the warning flags for category
. See Warning.[] for the categories.
216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'error.c', line 216
static VALUE
rb_warning_s_aset(VALUE mod, VALUE category, VALUE flag)
{
unsigned int mask = rb_warning_category_mask(category);
unsigned int disabled = warning_disabled_categories;
if (!RTEST(flag))
disabled |= mask;
else
disabled &= ~mask;
warning_disabled_categories = disabled;
return flag;
}
|
Instance Method Details
#warn(msg) ⇒ nil
Writes warning message msg
to $stderr. This method is called by Ruby for all emitted warnings.
237 238 239 240 241 242 243 244 |
# File 'error.c', line 237
static VALUE
rb_warning_s_warn(VALUE mod, VALUE str)
{
Check_Type(str, T_STRING);
rb_must_asciicompat(str);
rb_write_error_str(str);
return Qnil;
}
|