method
warn
v2_5_5 -
Show latest stable
- Class:
Kernel
warn(*args, p2 = {})public
If warnings have been disabled (for example with the -W0 flag), does nothing. Otherwise, converts each of the messages to strings, appends a newline character to the string if the string does not end in a newline, and calls Warning.warn with the string.
warn("warning 1", "warning 2") <em>produces:</em> warning 1 warning 2
static VALUE
rb_warn_m(int argc, VALUE *argv, VALUE exc)
{
VALUE opts, location = Qnil;
if (!NIL_P(ruby_verbose) && argc > 0 &&
(argc = rb_scan_args(argc, argv, "*:", NULL, &opts)) > 0) {
VALUE str = argv[0], uplevel = Qnil;
if (!NIL_P(opts)) {
static ID kwds[1];
if (!kwds[0]) {
CONST_ID(kwds[0], "uplevel");
}
rb_get_kwargs(opts, kwds, 0, 1, &uplevel);
if (uplevel == Qundef) {
uplevel = Qnil;
}
else if (!NIL_P(uplevel)) {
VALUE args[2];
long lev = NUM2LONG(uplevel);
if (lev < 0) {
rb_raise(rb_eArgError, "negative level (%ld)", lev);
}
args[0] = LONG2NUM(lev + 1);
args[1] = INT2FIX(1);
location = rb_vm_thread_backtrace_locations(2, args, GET_THREAD()->self);
if (!NIL_P(location)) {
location = rb_ary_entry(location, 0);
}
}
}
if (argc > 1 || !NIL_P(uplevel) || !end_with_asciichar(str, '\n')) {
VALUE path;
if (NIL_P(uplevel)) {
str = rb_str_tmp_new(0);
}
else if (NIL_P(location) ||
NIL_P(path = rb_funcall(location, rb_intern("path"), 0))) {
str = rb_str_new_cstr("warning: ");
}
else {
str = rb_sprintf("%s:%ld: warning: ",
rb_string_value_ptr(&path),
NUM2LONG(rb_funcall(location, rb_intern("lineno"), 0)));
}
RBASIC_SET_CLASS(str, rb_cWarningBuffer);
rb_io_puts(argc, argv, str);
RBASIC_SET_CLASS(str, rb_cString);
}
if (exc == rb_mWarning) {
rb_must_asciicompat(str);
rb_write_error_str(str);
}
else {
rb_write_warning_str(str);
}
}
return Qnil;
} Related methods
- Instance methods
- Array
- BigDecimal
- Complex
- Float
- Hash
- Integer
- Pathname
- Rational
- String
- __callee__
- __dir__
- __method__
- `
- abort
- at_exit
- autoload
- autoload?
- binding
- block_given?
- callcc
- caller
- caller_locations
- catch
- chomp
- chop
- eval
- exec
- exit
- exit!
- fail
- fork
- format
- gem_original_require
- gets
- global_variables
- gsub
- iterator?
- lambda
- load
- local_variables
- loop
- p
- pretty_inspect
- printf
- proc
- putc
- puts
- raise
- rand
- readline
- readlines
- require_relative
- select
- set_trace_func
- sleep
- spawn
- sprintf
- srand
- sub
- syscall
- system
- test
- throw
- trace_var
- trap
- untrace_var
- warn
- Class methods
- URI
- open
- pp
- Private methods
-
open_uri_original_open -
JSON -
URI -
gem -
j -
jj -
open -
open_uri_original_open -
pp -
require -
scanf -
y