Ruby / Lua / Perl 格式化工具
Reindent only — not a full formatter重新缩进 Ruby、Lua 或 Perl 源代码。一个工具,覆盖三种基于关键字的语言。
使用方法
- 1 选择语言:Ruby、Lua 或 Perl。
- 2 粘贴源代码。
- 3 调整缩进宽度——Ruby 通常用 2 个空格,Lua 和 Perl 可用 2 个或 4 个空格。
- 4 复制或下载处理结果。
为什么使用此工具
- 一个工具即可覆盖三种代码块开合语法相似、均基于关键字的语言。
- 各语言的代码块开始关键字不同:Ruby 用 <code class="rounded bg-slate-100 px-1 text-xs dark:bg-slate-800">do/end</code>,Lua 用 <code class="rounded bg-slate-100 px-1 text-xs dark:bg-slate-800">function/end</code>,Perl 则用花括号。
- 全部处理都在客户端完成——你的代码永远不会离开浏览器。
- 若需要符合规范的严格格式化结果,建议在本地使用 RuboCop(Ruby)、StyLua(Lua)或 perltidy(Perl)。
常见问题
这个工具和 RuboCop 兼容吗?
不兼容——本工具只做重新缩进。RuboCop 会应用数百条风格规则(cops);而我们只根据代码块开始关键字应用缩进规则。
工具能识别 here-doc 和字符串插值吗?
缩进是按行计算的,因此 here-doc 内容可能会被多加一层不必要的行首空格。如果文件中大量使用 here-doc,建议改用该语言专属的格式化工具。
为什么一个工具能同时支持三种语言?
因为它们的代码块结构十分相似——都是用一个关键字开启代码块,再用 <code class="rounded bg-slate-100 px-1 text-xs dark:bg-slate-800">end</code> 或 <code class="rounded bg-slate-100 px-1 text-xs dark:bg-slate-800">}</code> 结束。同一套规则引擎,三套关键字。
什么是 Ruby / Lua / Perl 格式化工具?
Ruby / Lua / Perl Formatter 是一款可直接在浏览器中重新缩进 Ruby、Lua 或 Perl 源代码的工具。它将三种基于关键字的语言整合进同一个格式化工具中,根据各语言的代码块结构应用一致的缩进规则,并且全部处理都在客户端完成。
功能特性
Keyword-block aware
Understands `end`-terminated blocks (Ruby/Lua) and brace blocks (Perl) to indent correctly.
Three languages
Pick Ruby, Lua, or Perl — each with the right block-open and block-close rules.
100% private
Runs client-side — your source is never uploaded.
示例
Input
class Foo
def bar(x)
return x*2
end
end
Output
class Foo
def bar(x)
return x*2
end
end
常见使用场景
-
1
Fix pasted scripts
Repair indentation on Ruby, Lua, or Perl copied from a chat or PDF.
-
2
Standardize nesting
Apply consistent 2-space nesting across a script.
-
3
Quick readability pass
Tidy layout before sharing without a full linter setup.
Zerethon's Ruby / Lua / Perl formatter reindents source in your browser, tracking keyword blocks (`def`/`do`/`end` in Ruby and Lua; braces in Perl) as well as literal brackets. It defaults to 2-space indentation. It is a lightweight reindenter, not a full RuboCop or perltidy — it fixes nesting without reflowing code. Nothing is uploaded.
- 分类
- 开发者
- 价格
- 免费
- 隐私
- 基于浏览器
- 注册
- 无需
References
- The Ruby Style Guide — rubystyle.guide
- Lua 5.4 Reference Manual — Lua.org
- perlstyle — Perl style guide — perldoc.perl.org
隐私
除非另有说明,否则你的数据永远不会离开浏览器。Ruby / Lua / Perl 格式化工具 完全在客户端运行 — 无需上传服务器,不记录日志,不追踪你输入的内容。
相关工具
在 Zerethon Social 上创作、分享与成长
免费注册。赚取积分,收集成就,与全球创作者建立联系。