Module: Warnings::Mixin

Defined in:
lib/warnings/mixin.rb

Instance Method Summary collapse

Instance Method Details

#warn(message) ⇒ nil

Registers a warning.

Examples:

warn "Foo#bar method will be removed in 1.0.0"

Parameters:

  • message (String)

    The warning message.

Returns:

  • (nil)


44
45
46
47
48
49
50
51
52
# File 'lib/warnings/mixin.rb', line 44

def warn(message)
  if warnings?
    $stderr.puts(message) if $DEBUG

    $WARNINGS << Warning.new(message,caller)
  end

  return nil
end

#warnings=(mode) ⇒ Boolean

Enables or disables warnings.

Parameters:

  • mode (Boolean)

    Specifies whether warnings will be enabled or disabled.

Returns:

  • (Boolean)

    Specifies whether warnings are enabled.



15
16
17
# File 'lib/warnings/mixin.rb', line 15

def warnings=(mode)
  @warnings = mode
end

#warnings?Boolean

Note:

Enabling $VERBOSE (ruby -w) or $DEBUG (ruby -d) will enable all warnings by default.

Determines whether warnings are enabled.

Returns:

  • (Boolean)

    Specifies whether warnings are enabled.



29
30
31
# File 'lib/warnings/mixin.rb', line 29

def warnings?
  ($VERBOSE || $DEBUG) || (@warnings != false)
end