A beautiful, feature-rich IRB alternative with:
β¨ Pretty Fonts & Colors - Beautiful syntax highlighting with colorized output
π§ Auto-Correct - Smart suggestions for common mistakes using did_you_mean
π€ AI Helper - Learn Ruby methods, best practices, and get code analysis
π History Manager - Search and replay command history
πΎ Snippet Manager - Save and reuse code snippets
π Variable Inspector - Inspect and analyze variables
β‘ Benchmarker - Performance testing and comparison
π Ruby Cheat Sheet - Quick reference for syntax and methods
β‘ Enhanced Readline - Better line editing with history support
π‘ Helpful Hints - Smart error messages with correction suggestions
Add this line to your Gemfile:
gem 'pretty_irb'Or install it yourself:
gem install pretty_irbLaunch Pretty IRB:
irb1
# or
pretty_irbTry some commands:
# Basic evaluation
1 + 2 # => 3
# String methods
"hello".upcase # => "HELLO"
# Array operations
[1, 2, 3].map { |x| x * 2 } # => [2, 4, 6]
# Get help
help # Show all commands
# Learn Ruby
?explain(map) # Explain the map method
?example(class) # See class examples
# Save and reuse code
snippet save double "[1,2,3].map { |x| x * 2 }"
snippet load double
# Search your history
history search "map"
# Inspect variables
varsCode is automatically syntax-highlighted with beautiful colors using the Rouge gem.
Common Ruby errors are automatically corrected and suggestions are provided:
- Method name typos (
.lenghtβ.length) - Variable name suggestions using
did_you_mean - Helpful error messages
Different data types are displayed with appropriate colors:
- Strings in blue
- Numbers in green
- Booleans in cyan
- Nil in gray
- Arrays and Hashes formatted nicely
Get instant help right in your REPL:
# Learn how a method works
pretty_irb >> ?explain(map)
# Get code examples
pretty_irb >> ?example(class)
# Learn best practices
pretty_irb >> ?practices(naming)
# Analyze your code for issues
pretty_irb >> ?debug("[1,2,3][0]")
# Quick reference
pretty_irb >> ?ref(operators)See AI_HELP.md for detailed documentation.
Never lose your commands again:
# Search previous commands
pretty_irb >> history search map
# View recent history
pretty_irb >> history last 10
# Export for sharing
pretty_irb >> history export my_session.rbSave and reuse code patterns:
# Save a useful snippet
pretty_irb >> snippet save double_array "[1,2,3].map { |x| x * 2 }"
# Load it later
pretty_irb >> snippet load double_array
# Search your snippets
pretty_irb >> snippet search arrayUnderstand your current state:
# List all variables
pretty_irb >> vars
# Inspect specific variable
pretty_irb >> vars name
# Find by type
pretty_irb >> vars type:String
# Memory usage
pretty_irb >> vars memoryMeasure and compare code performance:
# Benchmark code
pretty_irb >> bench "[1,2,3] * 100"
# Compare implementations
pretty_irb >> bench compare "(1..100).map { |x| x*2 }" vs "(1..100).collect { |x| x*2 }"
# Profile memory
pretty_irb >> bench memory "[1,2,3] * 1000"Quick reference without leaving REPL:
# General overview
pretty_irb >> cheat
# Array methods
pretty_irb >> cheat array
# String methods
pretty_irb >> cheat string
# Available topics: array, hash, string, enumerable, file, regex, dateErrors include color-coded messages and helpful hints:
NameError: undefined local variable or method `foo'
π‘ Did you mean?: for
exitorquit- Exit the shellhelp- Show available commandsclear- Clear the screen
history- Show all command historyhistory search KEYWORD- Search historyhistory last N- Show last N commandshistory export FILE- Export to filehistory clear- Clear history
snippet list- List saved snippetssnippet save NAME CODE- Save codesnippet load NAME- Load and executesnippet show NAME- View snippet detailssnippet delete NAME- Delete snippetsnippet search KEYWORD- Search snippets
vars- List all variablesvars VARNAME- Inspect variablevars type:TYPE- Find by typevars search:KEYWORD- Search variablesvars memory- Memory usage
bench CODE- Benchmark codebench compare CODE1 vs CODE2- Comparebench memory CODE- Profile memory
cheat- Show general cheat sheetcheat TOPIC- Topic cheat sheet (array, hash, string, enumerable, file, regex, date)
?explain(method)- Explain a method?example(topic)- Get code examples?debug(code)- Analyze code?practices(topic)- Learn best practices?ref(keyword)- Quick reference
- AI_HELP.md - AI Helper features and examples
- ADVANCED_FEATURES.md - Advanced features guide with workflows
- QUICK_REFERENCE.md - Command quick reference
- CHANGELOG.md - Version history and changes
Setup:
# Clone the repo
git clone https://github.com/j14as/pretty_irb.git
cd pretty_irb
# Install dependencies
bundle installRun tests:
rake specTry it locally:
bin/console
# or
ruby -I lib exe/pretty_irbBuild the gem:
gem build pretty_irb.gemspecWe welcome bug reports, feature requests, and pull requests!
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow Ruby style guide (use rubocop)
- Add tests for new features
- Update documentation as needed
- Keep commits atomic and well-described
- Use the GitHub Issues
- Include Ruby version and OS details
- Provide minimal reproduction steps
The gem is available as open source under the terms of the MIT License.
This gem is inspired by:
- Ruby's IRB - Interactive Ruby Shell
- Python's IPython - Advanced interactive computing
- Node.js REPL - Autocomplete and code introspection
- Pry - Advanced Ruby debugging and exploration
Special thanks to:
- Rouge - Syntax highlighting
- Reline - Enhanced readline
- did_you_mean - Smart error suggestions
- Colorize - Terminal colors
Made with β€οΈ by Jayesh
If you find Pretty IRB helpful, please consider:
- β Starring the repository
- π Reporting issues
- π‘ Suggesting features
- π Improving documentation