Ruby Code Prettifier & Indenter
Paste messy Ruby code to prettify with proper indentation and consistent formatting
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
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.
def create
@user = User.new(user_params)
if @user.save
redirect_to @user
else
render :new
end
end
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.
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
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.
begin
result = api_call(params)
rescue Timeout::Error => e
retry if attempts < 3
rescue StandardError => e
log_error(e)
ensure
connection.close
end
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
Quick cleanup before committing controller or model code that got messy during debugging.
Reformatting Chef recipes and Vagrant provisioning scripts without installing extra gems.
Making homework submissions readable before turning them in — professors notice messy indentation.
Reformatting a snippet from a PR to read it more clearly without pulling down the branch.
Common Mistakes
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.
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.
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
- Processing: 100% client-side — nothing leaves your browser
- Browser Support: Chrome, Firefox, Safari, Edge
- Ruby Versions: Handles Ruby 1.9 through 3.x syntax
- Indentation Options: 2 spaces (default), 4 spaces, tabs
- Max Input: No hard limit — tested with files over 10,000 lines
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.