sp = []
kp = []
out = ""
src = DATA.read + "\n__END__"
src.split(/\n/).each do | s |
s.each_byte.each_with_index.inject( false ) do | b , ( c , i ) |
b || if c.chr != " "
sp.push i
if s =~ /if|for|each|class|def/
kp.push i
end
true
end # if
end # injct
if sp[sp.size-2] > sp[sp.size-1]
endf = nil
loop do
m = kp.pop
if (endf and m == endf) || (m.nil? || sp.last > m)
kp.push m
# print:bre
# p s
endf = nil
break
end
endf = m
tmp = "end".rjust(3+m," ")
out << tmp+"\n"
end
end
if s =~ /\s?.*(end)\s?.*/
else
out << s+"\n"
end
end # each
#p sp
#p kp
puts out
eval out
__END__
class A
def func
for i in 1..9
for n in 1..9
printf "%02d " % ( i * n )
puts
end
A.new.func