The following code gives me
NameError: undefined local variable or method `dir'
in extract_snapshots method.
The code is intended to extract snapshots from a video, store them in a created temporary directory, send the snapshots to a service and remove the directory after.
def perform
using_temporary_directory do |dir|
extract_snapshots
send_snapshots
end
end
def using_temporary_directory(&b)
Dir.mktmpdir { |dir| b.call(dir) }
end
def extract_snapshots
system "ffmpeg -i #{video_file_path} -vf fps=1/#{INTERVAL} #{dir}/%04d.jpg"
end
I thought, that dir variable should be visible in extract_snapshots and send_snapshots, because it is on the same level. But it isn't in the scope of those methods. Is it possible to make dir variable visible without doing the following:
def perform
using_temporary_directory do |dir|
extract_snapshots(dir)
send_snapshots(dir)
end
end
?