Skip to content

Instantly share code, notes, and snippets.

@zhhailon
Created November 29, 2011 08:39
Show Gist options
  • Save zhhailon/1404033 to your computer and use it in GitHub Desktop.
Save zhhailon/1404033 to your computer and use it in GitHub Desktop.
To make comments like "/////////34//////////////" in order.
# Created by ZHANG Hailong <[email protected]>
#
# This is a tool to serialize comments in specific style into the right order.
# For example:
# Before
# //////////////3//////////////////
# //////////////6//////////////////
# //////////////0//////////////////
# After
# //////////////0//////////////////
# //////////////1//////////////////
# //////////////2//////////////////
#
file_name = ARGV[0]
puts file_name
pre_number = 0
data = nil
open(file_name, "r") do |f|
data = f.read
data.gsub!(/\/+[0-9]+\/+/) do |match|
number = match.tr('/', '')
match.gsub!("/#{number}/", pre_number.to_s) if number != pre_number.to_s
puts match
pre_number += 1
match
end
end
open(file_name, "w") do |f|
f.write(data)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment