Expanding on @maerics' answer ,the below ignores . && ..
, regex based filter , and select the latest file if desired.
Dir.chdir(in_dir)
target_file = Dir.entries(in_dir).select(|x|
x != '.' &&
x != '..' &&
x =~ /\somefile.txt\z/).sort_by{|f|File.mtime(f)}.last(1)
puts "here i am #{target_file}"