Tools

Home
JSON FormatterSQL FormatterJS ValidatorMinify CSS
Merge PDFCompress PDFImage to PDF
JPG to PNGPNG to WebPCrop Image

Ruby Code Prettifier & Indenter

Paste messy Ruby code to prettify with proper indentation and consistent formatting

Your files never leave your browser
Input0 chars, 0 lines
Output0 chars, 0 lines
Ready·

Paste messy Ruby — controllers, Rake tasks, Gemfiles, whatever — and get clean, properly indented code back in one click. Handles def...end, do...end, if/elsif/else, case/when, nested modules, and all the block constructs that drift out of alignment after a few merges. And everything runs in your browser. Nothing gets uploaded.

How It Works

Paste Ruby Code
→
Parse & Reindent
→
Clean Output

The formatter scans each line for Ruby keywords that open blocks (class, module, def, do, if, unless, begin, case) and tracks when they close with end. It rebuilds indentation from scratch based on nesting depth, so even code with wildly inconsistent spacing comes out clean. Inline blocks and single-line methods stay on one line — the formatter won't break what's already compact.

Examples

Fixing a Messy Controller Method

A teammate committed code with zero consistent indentation. Classic.

INPUT
def create @user = User.new(user_params) if @user.save redirect_to @user else render :new end end
OUTPUT
def create @user = User.new(user_params) if @user.save redirect_to @user else render :new end end

Nested Module and Class

Deep nesting with modules wrapping classes — the kind of thing that drifts out of alignment after a few merges.

INPUT
module Admin class UsersController < ApplicationController def index @users = User.all.order(:name) respond_to do |format| format.html format.json { render json: @users } end end end end
OUTPUT
module Admin class UsersController < ApplicationController def index @users = User.all.order(:name) respond_to do |format| format.html format.json { render json: @users } end end end end

Begin/Rescue Error Handling

Error handling blocks are especially easy to misindent when you're editing in a hurry.

INPUT
begin result = api_call(params) rescue Timeout::Error => e retry if attempts < 3 rescue StandardError => e log_error(e) ensure connection.close end
OUTPUT
begin result = api_call(params) rescue Timeout::Error => e retry if attempts < 3 rescue StandardError => e log_error(e) ensure connection.close end

Who Uses This

💻 Rails Developers

Quick cleanup before committing controller or model code that got messy during debugging.

🔧 DevOps Engineers

Reformatting Chef recipes and Vagrant provisioning scripts without installing extra gems.

📚 Students

Making homework submissions readable before turning them in — professors notice messy indentation.

👀 Code Reviewers

Reformatting a snippet from a PR to read it more clearly without pulling down the branch.

Common Mistakes

Pasting code with syntax errors

If your Ruby has a missing end or unmatched do, the formatter can't guess where blocks close. The output will look off. Fix the syntax error first, then format.

Expecting RuboCop-level style changes

This tool fixes indentation and spacing. It won't rename variables, convert { } blocks to do...end, or enforce guard clauses. For that, you still need a linter.

Formatting ERB templates as plain Ruby

ERB files mix HTML and Ruby with <%= %> tags. This formatter handles pure .rb files. Pasting an ERB view will produce garbled output — use an HTML formatter for those instead.

Technical Details

Frequently Asked Questions

How do I format Ruby code online?

Paste your Ruby code into the input panel, pick your indentation style (2 spaces is the Ruby standard), and click Beautify. The formatted code appears instantly on the right side. Copy it or download it as a .rb file.

Does the Ruby formatter change my code logic?

No. It only touches whitespace and indentation. Variable names, method calls, string contents, comments — all of that stays exactly the same. Your code will run identically after formatting.

What Ruby block types does it support?

All of them. class, module, def, do...end, if/elsif/else, unless, case/when, begin/rescue/ensure, and while/until loops. It also handles Ruby 3.x pattern matching with case/in.

Is my Ruby code uploaded to a server?

Nope. Everything happens in your browser with JavaScript. Your code stays on your machine and is never transmitted anywhere. You can disconnect from the internet and the formatter still works perfectly.

What's the difference between beautify and minify?

Beautify adds proper indentation and spacing so humans can read the code easily. Minify does the opposite — it strips unnecessary whitespace and blank lines to make the file as small as possible. Most people want beautify; minify is useful when you're embedding Ruby in a constrained environment.

Share: