Getting Started¶
This guide will help you start using DebugMe in your Ruby projects.
Shorthand Syntax¶
Before diving in, note that DebugMe supports a convenient shorthand for the tag option:
# These two calls are equivalent:
debug_me(tag: 'PAYMENT') { :amount }
debug_me('PAYMENT') { :amount }
When the first argument is a string, it's automatically used as the tag. This shorthand works with all other options too:
Basic Setup¶
1. Require and Include¶
The include DebugMe statement makes the debug_me method available in your current scope.
Include Options
You can include DebugMe at different levels:
- Top level (global): Available everywhere in your application
- In a base class: Available in that class and subclasses
- In specific classes: Available only where included
- Not at all: Use
DebugMe.debug_me { :var }instead
For Rails apps, set up an initializer to configure defaults once. See Configuration for details.
2. Your First Debug Statement¶
Output:
Inspecting Variables¶
Single Variable¶
Use a symbol to inspect one variable:
Multiple Variables¶
Use an array of symbols for multiple variables:
Output:
All Local Variables¶
Call with an empty block to show all local variables:
Instance Variables¶
Prefix with @ to inspect instance variables:
class User
def initialize(name)
@name = name
@created_at = Time.now
debug_me { [:@name, :@created_at] }
end
end
User.new("Bob")
Class Variables¶
Prefix with @@ to inspect class variables:
Expressions¶
Pass strings to evaluate expressions:
Output:
DEBUG [2025-01-06 12:30:45.123456] example.rb:3
numbers.sum -=> 15
DEBUG [2025-01-06 12:30:45.123457] example.rb:4
numbers.size -=> 5
Customizing Output¶
Custom Tag¶
Without Header¶
Output:
Without Timestamp¶
Enabling and Disabling¶
Global Control¶
Environment Variable¶
# Disable debug output
DEBUG_ME=false ruby my_script.rb
# Enable debug output
DEBUG_ME=true ruby my_script.rb
Next Steps¶
- Learn about all Configuration Options
- See more Usage Examples
- Read the API Reference
- Review Security Considerations