Module: Tins::P
- Included in:
- Object
- Defined in:
- lib/tins/p.rb
Overview
A module that provides debugging methods for inspecting objects by raising exceptions with their inspected representations.
This module adds p! and pp! methods that raise RuntimeError exceptions containing the inspected or pretty-inspected output of objects, making it easy to quickly debug values during development without printing to stdout.
Instance Method Summary collapse
-
#p!(*objs) ⇒ Object
private
Raises a RuntimeError with the inspected representation of the given objects.
-
#pp!(*objs) ⇒ Object
private
Raises a RuntimeError with the pretty-inspected representation of the given objects.
Instance Method Details
#p!(*objs) ⇒ Object (private)
Raises a RuntimeError with the inspected representation of the given objects.
This method is useful for quick debugging by raising an exception that contains the inspected output of the provided objects. It behaves similarly to Ruby’s built-in p
method but raises an exception instead of printing to stdout.
35 36 37 |
# File 'lib/tins/p.rb', line 35 def p!(*objs) raise((objs.size < 2 ? objs.first : objs).inspect) end |
#pp!(*objs) ⇒ Object (private)
Raises a RuntimeError with the pretty-inspected representation of the given objects.
This method is useful for quick debugging by raising an exception that contains the pretty-printed output of the provided objects. It behaves similarly to Ruby’s built-in pp
method but raises an exception instead of printing to stdout.
55 56 57 |
# File 'lib/tins/p.rb', line 55 def pp!(*objs) raise("\n" + (objs.size < 2 ? objs.first : objs).pretty_inspect.chomp) end |