Created
September 18, 2011 18:12
-
-
Save mitio/1225338 to your computer and use it in GitHub Desktop.
Quick and dirty eigenclass-defined class methods in Ruby
This file contains hidden or 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
code = File.read(ARGV.first) | |
eigenclass = false | |
methods = 0 | |
identation = '' | |
code.split("\n").each do |line| | |
case line | |
when /^(\s*)class\s+<<\s+self\b/ | |
eigenclass = true | |
identation = $1 | |
when /\bdef\b/ | |
methods += 1 if eigenclass | |
when /^#{identation}end\b/ | |
eigenclass = false | |
end | |
end | |
puts "#{methods}\t#{ARGV.first}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment