Skip to content

Instantly share code, notes, and snippets.

@manveru
Created March 23, 2011 11:18
Show Gist options
  • Save manveru/882958 to your computer and use it in GitHub Desktop.
Save manveru/882958 to your computer and use it in GitHub Desktop.
Find random excerpts of code from Ramaze
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