Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 17 lines (12 sloc) 387 Bytes
#!/usr/bin/env ruby
#
# Converts camelCase to snake_case in the given input.
#
# Written in 2010 by Suraj N. Kurapati <https://github.com/sunaku>
input = ARGF.read
# remove the 'a' argument prefix
input.gsub!(/\ba([A-Z])([a-z]+)/) { $1.downcase + $2 }
# convert camel case to snake case
while input.gsub!(/\b([a-z_]+)([A-Z])([a-z]+)/) { $1 + '_' + $2.downcase + $3 }
end
print input