Ruby comment remover

Remove comments from
Ruby code.

Strip comments from Ruby code online. Handles =begin/=end blocks, shebangs, and string interpolation safely.

Free, no signup Runs in your browser Instant, no upload Works on .rb files

Before and after

Real-world Ruby code on the left. The same code with every comment removed on the right.

ruby-input.rb
#!/usr/bin/env ruby
# Order processor

require "json"

=begin
This is a long-form block comment
explaining how the processor works.
=end

class OrderProcessor
  # Initialize with a queue
  def initialize(queue)
    @queue = queue # remember
  end

  # Process the next message
  def process_one
    message = @queue.pop  # blocking call
    payload = JSON.parse(message)
    puts "Processing #{payload['id']}" # not a comment
  end
end
ruby-output.rbcleaned
#!/usr/bin/env ruby

require "json"


class OrderProcessor
  def initialize(queue)
    @queue = queue
  end

  def process_one
    message = @queue.pop
    payload = JSON.parse(message)
    puts "Processing #{payload['id']}"
  end
end
Why use it

Built for Ruby specifically.

Ruby code in tutorials and Rails generators tends to ship with rich comment scaffolding, explanations, route stubs, deprecation notes. When you want a clean snippet, removing them by hand is tedious. Uncommenter strips all comment styles while leaving string interpolation, symbols, and DSL syntax untouched.

  • # line comments removed
  • =begin / =end block comments removed
  • Shebang preserved by default (#!/usr/bin/env ruby)
  • String interpolation #{...} kept intact
  • Auto-detected from .rb, .rake, and .gemspec files
How it works

Strip comments in 30 seconds.

  1. 1

    Open the tool

    Head to uncommenter.com/tool. Nothing to install. Nothing to sign up for.

  2. 2

    Paste your Ruby code

    Drop your .rb file in, or paste code into the editor. Auto-detection picks up Ruby from the extension or file content.

  3. 3

    Click 'Remove Comments'

    The parser walks every character with a real state machine, strings, regex, and other context-sensitive parts are detected and left alone.

  4. 4

    Copy or download

    Grab the cleaned output. Your code never left your browser.

FAQ

Ruby questions, answered.

Does it remove =begin/=end blocks?

+

Yes. Ruby's block comment syntax is treated like any other multi-line comment.

Will the shebang stay?

+

Yes by default. Toggle the 'preserve shebangs' option off if you want it removed.

What about strings containing #?

+

String literals are tracked as a separate state, so a "#hashtag" string or a #{interpolation} expression is preserved. The # is only treated as a comment marker outside of strings.

Other languages

Working in something else?

Plus 35+ more languages supported in the live tool , including HTML, YAML, Dockerfile, Terraform, Solidity, and more.

Try it on your Ruby code now.

Free forever. No signup. No upload. Runs entirely in your browser.

Open uncommenter