Input

Output

What is Ruby?

Ruby is a dynamic, object-oriented programming language known for its elegant syntax and developer-friendly design. It is the language behind the Ruby on Rails web framework.

The Ruby Formatter normalizes indentation (2 spaces), handles def/end, class/end, and do/end blocks, and removes trailing whitespace. You can find gems and libraries for your projects on RubyGems.

How to Use

1

Paste your Ruby code

Drop a model, a rake task or a whole script into the left editor. Upload opens an .rb file from disk, and Sample loads a small User class to try it on.

2

Formats as you type

About 300 ms after you stop typing, the right pane shows the result. Every line is trimmed and shifted two spaces for each open def, if, do |x| or bracket, while else, rescue and ensure step back one level. Spacing inside a line is left exactly as you wrote it.

3

Copy or download

Grab the re-indented code with Copy, or press Download for a script.rb you can rename and drop back into the app.

Formatting Example

Example: Format a Ruby class

Unformatted input:

class User
attr_accessor :name, :age

def initialize(name, age)
@name = name
@age = age
end

def greet
"Hello, #{@name}!"
end
end

Formatted output:

class User
  attr_accessor :name, :age

  def initialize(name, age)
    @name = name
    @age = age
  end

  def greet
    "Hello, #{@name}!"
  end
end

Frequently Asked Questions

Does the formatter handle Ruby blocks with do/end?

Yes. The formatter recognizes do and end as block delimiters and applies proper indentation to lines within those blocks.

Can I format Ruby on Rails files?

Yes. Rails files are standard Ruby files. You can paste the content of any .rb file including models, controllers, and migrations.

Does this replace RuboCop?

This is a lightweight indentation formatter, not a full linter. For production Ruby projects, RuboCop provides comprehensive style enforcement following the Ruby Style Guide. This tool is ideal for quick cleanup and readability.

Is my Ruby code safe when I use this tool?

Yes. The re-indent is a short line-by-line loop in this page's own script and it never makes a request, so pasting an initializer that still holds an API key does not send that key anywhere. Download builds its file in the browser as well.

Related Tools