Method: Warning#warn

Defined in:
error.c

#warn(msg, category: nil) ⇒ nil

Writes warning message msg to $stderr. This method is called by Ruby for all emitted warnings. A category may be included with the warning.

See the documentation of the Warning module for how to customize this.

Returns:

  • (nil)

286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'error.c', line 286

static VALUE
rb_warning_s_warn(int argc, VALUE *argv, VALUE mod)
{
    VALUE str;
    VALUE opt;
    VALUE category = Qnil;

    rb_scan_args(argc, argv, "1:", &str, &opt);
    if (!NIL_P(opt)) rb_get_kwargs(opt, &id_category, 0, 1, &category);

    Check_Type(str, T_STRING);
    rb_must_asciicompat(str);
    if (!NIL_P(category)) {
        rb_warning_category_t cat = rb_warning_category_from_name(category);
        if (!rb_warning_category_enabled_p(cat)) return Qnil;
    }
    rb_write_error_str(str);
    return Qnil;
}