Class: Dir

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/extend/dir.rb

Overview

– – Reopen the core ruby Dirctory class and add the below methods to it. –

Instance Method Summary collapse

Instance Method Details

#ascii_order_file_starting_with(starts_with_string) ⇒ Object

– – Put all the files starting with the given string in – alphabetical ascending order and then return the file – that comes last. – – Throw an exception if no file in this folder starts – with the given string –



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/utils/extend/dir.rb', line 16

def ascii_order_file_starting_with starts_with_string

  recently_added_file = nil
  filepath_leadstr = File.join self.path, starts_with_string
  Dir.glob("#{filepath_leadstr}*").sort.each do |candidate_file|

    next if File.directory? candidate_file
    recently_added_file = candidate_file

  end

  Throw.if_nil recently_added_file
  Throw.if_not_exists recently_added_file
  return recently_added_file

end