Skip to content

Instantly share code, notes, and snippets.

@mitio
Created September 18, 2011 18:12
Show Gist options
  • Save mitio/1225338 to your computer and use it in GitHub Desktop.
Save mitio/1225338 to your computer and use it in GitHub Desktop.
Quick and dirty eigenclass-defined class methods in Ruby
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