if getline(lnum) =~ '^\s*\(module\>\|class\>\|def\>\|if\>\|for\>\|while\>\|until\>\|else\>\|elsif\>\|case\>\|when\>\|unless\|begin\|ensure\>\|rescue\>\)'
\ || getline(lnum) =~ '{\s*$'
\ || getline(lnum) =~ '\({\|\<do\>\).*|.*|\s*$'
\ || getline(lnum) =~ '\<do\>\(\s*#.*\)\=$'
let ind = ind + &sw
let flag = 1
endif
" Subtract a 'shiftwidth' after lines ending with
" "end" when they begin with while, if, for, until
if flag == 1 && getline(lnum) =~ '\<end\>\(\s*#.*\)\=$'
let ind = ind - &sw
endif
" Subtract a 'shiftwidth' on end, else and, elsif, when and }
if getline(v:lnum) =~ '^\s*\(end\>\|else\>\|elsif\>\|when\>\|ensure\>\|rescue\>\|}\)'