Class: Object

Inherits:
BasicObject
Defined in:
lib/core_ext/object.rb

Instance Method Summary collapse

Instance Method Details

#info(message, color: :black) ⇒ Object

Issue an informational message.

Parameters:

  • message (String)

    informational message



32
33
34
# File 'lib/core_ext/object.rb', line 32

def info(message, color: :black)
  puts message.send(color)
end

#verbose_info(message, color: :blue) ⇒ Object

Issue a verbose informational message.

Parameters:

  • message (String)

    verbose informational message



39
40
41
# File 'lib/core_ext/object.rb', line 39

def verbose_info(message, color: :blue)
  info(message, color: color) if $VERBOSE_INFO
end

#warn(message, pry:) ⇒ Object

Issue a warning and maybe open a Pry session attached to the error or binding passed.

Examples:

with error context

begin
  (...)
rescue => error
  warn("oops", pry: error)
end

with binding context

warn("oops", pry: binding)

Parameters:

  • message (String)

    warning message

  • pry (Exception, Binding, nil)

    attach the Pry session to this error or binding



18
19
20
21
22
23
24
25
26
27
# File 'lib/core_ext/object.rb', line 18

def warn(message, pry:)
  $WARN_COUNTER = $WARN_COUNTER.to_i + 1
  Kernel.warn "WARNING #{$WARN_COUNTER}: #{message}".red
  if $PRY_ON_WARN == true || $PRY_ON_WARN == $WARN_COUNTER
    case pry
      when Exception then Pry::rescued(pry)
      when Binding then pry.pry
    end
  end
end