Unlocking spreadsheet files quickly - follow-up I recently posted a program I made to unlock spreadsheet files( see also ), I've taken all of your advice and made it more Ruby like, it has no shell commands in it, and uses FileUtils

I personally think it looks a whole lot cleaner and a whole lot more Ruby like. I would like a critique on my work so far, and would like some pointers if possible.

Source:

#!/usr/local/bin/ruby

require 'fileutils'

def spreadsheet_unlocker
    puts "Enter Folio # if unlocking multiple seperate with comma followed by space."
    folios = gets.chomp
    folios.split(', ').each do |input_folio|
        lockfile = "/my/dir.~lock.#{input_folio}.ods#"
        if input_folio =~ /^\d{7}/ 
            if File.exist?( lockfile )
                puts "Unlock file?"
                input = gets.chomp
                    if input =~ /y/i
                     FileUtils.rm( lockfile )
                     puts "File unlocked."
                else
                    puts "You went through that trouble for no reason..."
                end
            else
                puts &lt;&lt;-EDE.gsub(/^\s*&gt;/, ' ') 
                &gt;
                &gt;Lockfile not found for Folio # #{input_folio}"
                &gt;
                &gt;If the file name doesn't match the folio number, get the file name
                &gt;and use that instead of the Folio number...
                &gt;
                EDE
                spreadsheet_unlocker
            end
        else
            puts &lt;&lt;-EDF.gsub(/^\s*&gt;/, ' ')
            &gt;
            &gt;What part of 'Folio #' is hard to understand? 7 DIGITS"
            &gt;
            &gt;If the file name doesn't match the folio number, get the file name
            &gt;and use that instead of the Folio number...
            &gt;
            EDF
            spreadsheet_unlocker
        end
    end
end
spreadsheet_unlocker


Example usage:

Enter Folio # if unlocking multiple seperate with comma followed by space.
1111111, 2222222, 3333333
Unlock file?
yes
File unlocked.
Unlock file?
yes
File unlocked.
Unlock file?
yes
File unlocked.




Enter Folio # if unlocking multiple seperate with comma followed by space.
2345678

 Lockfile not found for Folio # 2345678"

 If the file name doesn't match the folio number, get the file name
 and use that instead of the Folio number...
Good job listening to feedback. Keep at it.


Use two spaces to indent.
Name your methods verbs, not nouns (e.g., unlock_spreadsheet).
Split on comma and then use strip to remove leading and trailing whitespace.
Rather than calling the method recursively, you may want to put a loop do around the method and then break when you're done.
If you run Rubocop, you'll see that your method is too long. Instead, you can move each set of actions inside of if and else blocks into their own methods.