replace for loop with block

make it as pure ruby