Created
December 10, 2016 20:37
-
-
Save smileart/643808b69148d95ec004eb90c5a299b3 to your computer and use it in GitHub Desktop.
Ruby "minification" script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# 1) Require this script | |
# 2) Call MiniRuby.minify | |
# 3) Get one line as STDOUT | |
class MiniRuby | |
def self.minify | |
code = File.read($0) | |
code.sub! /^([^#\R\n]*?)MiniRuby.minify(.*)$/, '' | |
code.sub! /require(_relative)? ["|'](.*?)mini_ruby(\.rb)?["|']/, '' | |
code_line = code.lines.map(&:strip).reject(&:empty?).reject {|l| l =~ /^#/}.join('; ') | |
puts code_line | |
exit | |
end | |
end | |
# MiniRuby.minify |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment