Module: AmazingTap::ObjectExtension

Included in:
Object
Defined in:
lib/amazing_tap.rb

Instance Method Summary collapse

Instance Method Details

#tapp(label = nil, type: AmazingTap.show_type, backtrace: false) ⇒ self Also known as: tapap

Prints the receiver via amazing_print with a labeled header, then returns it, so calls chain safely. Without an explicit label, the label is inferred from the receiver expression at the call site; when inference fails the header shows only the class.

Parameters:

  • label (Symbol, nil) (defaults to: nil)

    explicit label; nil infers from the call site

  • type (Boolean) (defaults to: AmazingTap.show_type)

    append the receiver's class to the header

  • backtrace (Boolean, Integer) (defaults to: false)

    print all caller frames (true) or the first N frames (Integer) after the output

Returns:

  • (self)

Raises:

  • (ArgumentError)

    when label is neither nil nor a Symbol



98
99
100
101
102
103
104
# File 'lib/amazing_tap.rb', line 98

def tapp(label = nil, type: AmazingTap.show_type, backtrace: false)
  raise ArgumentError, "label must be a Symbol" unless label.nil? || label.is_a?(Symbol)

  label ||= AmazingTap.infer_label(caller_locations(1, 1).first)
  AmazingTap.print_labeled(self, label, callers: caller, type: type, backtrace: backtrace)
  self
end