Square.rb is a Python-based Ruby script executor that allows you to run Ruby code without installing Ruby on your system. It's designed to be portable and self-contained, perfect for SquareCloud environments.
- No Ruby Installation Required - Runs Ruby scripts using portable runtime
- Automatic Gem Management - Installs gems from Gemfile automatically
- Interactive Mode - Run Ruby code interactively like IRB
- Cross-Platform - Works on Windows, macOS, and Linux
- Error Handling - Graceful error handling with detailed output
- Self-Contained - Everything stays in the project directory
# Run default script (automatically finds start.rb, main.rb, app.rb, or index.rb)
python main.py
# Run a specific Ruby script
python main.py hello.rb
# Run with arguments
python main.py app.rb --port 3000 --host 0.0.0.0
# Interactive mode
python main.py --interactive
# Install gems from Gemfile
python main.py --install-gems- 
Place Ruby Binary (Optional): Square.rb will try to download Ruby automatically, but you can also place a Ruby binary in the ruby_runtime/directory.
- 
Create Your Ruby Script: Write your Ruby code in any .rbfile. Create astart.rbfile to run automatically when no script is specified.
- 
Add Dependencies (Optional): Create a Gemfilewith your required gems. Gems are installed automatically when scripts run.
- 
Environment Variables (Optional): Create a .envfile to set environment variables that will be loaded automatically.
- 
Run: Use python main.pyto run the default script, orpython main.py your_script.rbto execute a specific Ruby script.
# start.rb - Runs automatically when no script specified
puts "Welcome to Square.rb!"
puts "Environment: #{ENV['SQUARE_ENVIRONMENT']}"# hello.rb
puts "Hello from Square.rb!"
puts "Ruby version: #{RUBY_VERSION}"# app.rb
require 'json'
data = { name: "Square.rb", version: "1.0" }
puts JSON.pretty_generate(data)$ python main.py --interactive
Square.rb Interactive Ruby Mode
Type 'exit' or 'quit' to exit
----------------------------------------
ruby> puts "Hello World!"
Hello World!
ruby> 2 + 2
4
ruby> exit
squarerb/
├── main.py              # Main Python script
├── start.rb             # Default script (auto-runs when no args)
├── hello.rb             # Sample Ruby script
├── Gemfile              # Sample Gemfile
├── .env                   # Environment variables (optional)
├── ruby_runtime/        # Ruby runtime directory (auto-created)
│   ├── bin/            # Ruby binaries
│   ├── gems/           # Installed gems
│   └── bundle/         # Bundle cache
└── README.md
- python main.py- Run default script (start.rb, main.rb, app.rb, or index.rb)
- python main.py script.rb [args...]- Execute a Ruby script with optional arguments
- python main.py --interactive- Start interactive Ruby mode
- python main.py --install-gems- Install gems from Gemfile
- python main.py --help- Show help information
- Runtime Detection: Square.rb detects your platform and architecture
- Ruby Acquisition: Downloads appropriate Ruby runtime if not present
- Environment Setup: Configures Ruby environment variables and loads .env file
- Gem Installation: Automatically installs gems from Gemfile (no manual intervention needed)
- Script Execution: Runs your Ruby script with proper error handling
- Default Script: Automatically finds and runs start.rb when no script is specified
- Windows (x64, x86)
- macOS (Intel, Apple Silicon)
- Linux (x64, x86)
Square.rb provides comprehensive error handling:
- Missing Scripts: Clear error messages for missing Ruby files
- Runtime Errors: Captures and displays Ruby errors with stack traces
- Timeout Protection: Scripts timeout after 5 minutes to prevent hanging
- Graceful Degradation: Falls back to manual Ruby installation if automatic download fails
- Default Script: Create a start.rbfile to run automatically when no arguments are provided
- Environment Variables: Use .envfile to set environment variables automatically
- Gems: Gems are installed automatically from Gemfile - no manual bundle install needed
- Performance: First run may be slower due to Ruby runtime download
- Debugging: Use --interactivemode for testing small code snippets
- Portability: Keep everything in the project directory for easy deployment
- Square.rb will attempt to download Ruby automatically
- You can manually place Ruby binary in ruby_runtime/directory
- Check your internet connection
- Verify Gemfile syntax
- Try running python main.py --install-gemsseparately
- Check Ruby script syntax
- Verify required gems are in Gemfile
- Use --interactivemode for debugging
This project is open source and available under the MIT License.
Square.rb - Making Ruby accessible everywhere, no installation required!