The reason it will not work is because new
and each
are two different methods, so they do not have access to each other's parameters. To โdevelopโ your code, you might consider creating a new method that would contain two method calls and pass it a repeating parameter:
def do_something(dir) Dir.new(dir).each do |file|
The fact that creating a new method has such low overhead means that it is quite reasonable to create one for such a small piece of code as this, and this is one of many reasons why Ruby is so nice to use the language with.
source share