Created
March 23, 2011 11:18
-
-
Save manveru/882958 to your computer and use it in GitHub Desktop.
Find random excerpts of code from Ramaze
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
require 'ramaze' | |
max = 40 | |
final = [] | |
Dir.glob("#{Ramaze::ROOT}/**/*.rb") do |path| | |
blocks = [] | |
File.open path do |file| | |
block = [] | |
indent = nil | |
file.each_line do |line| | |
if line =~ /^(\s*)(def.{,#{max}})$/ | |
block << $2 | |
indent = $1.size | |
elsif block.size > 10 | |
block.clear | |
elsif block.first && line =~ /^\s{#{indent}}(end)$/ | |
block << $1 | |
blocks << block | |
block = [] | |
elsif block.first | |
if line =~ /^\s{#{indent}}( .{,#{max}})$/ | |
block << $1 | |
elsif line =~ /^\s*$/ | |
block << '' | |
else | |
block.clear | |
end | |
end | |
end | |
end | |
final << blocks.select{|b| b.size > 4 }.sample | |
end | |
puts final.compact.sample |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment