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")


  warning 1
  warning 2

If the uplevel keyword argument is given, the string will be prepended with information for the given caller frame in the same format used by the rb_warn C function.

  # In baz.rb
  def foo
    warn("invalid call to foo", uplevel: 1)

  def bar



  baz.rb:6: warning: invalid call to foo
Show source
Register or log in to add new notes.