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

Paste raw or messy Ruby source code into the left editor, or click Upload to load a .rb file.

2

Instant formatting

The formatter automatically normalizes indentation (2 spaces), handles Ruby block keywords, and cleans up whitespace.

3

Copy or download

Use the Copy button to copy the result, or Download to save it as a script.rb file.

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, completely. All formatting runs directly in your browser — no code is ever sent to a server. Your Ruby source stays private and secure at all times.

Related Tools