2013-05-29 212 views
0

在程序的下半部分的獲取部分,終端不要求我輸入,而是自動輸入。我無法理解這是怎麼發生的。紅寶石腳本錯誤

的代碼是:

puts "Welcome to my automatic file opener" 
puts "Version - 2.0" 

if ARGV[0] && ARGV[1] #to ensure Arguements are given as input 
old_data = File.open(ARGV[0]).readlines 
new_data = File.open(ARGV[1]).readlines 

class Differentiator 

def old_stuff 
    puts "the old files are:-" 
    puts old_data 
end 

def new_stuff 
    puts "The new files are:-" 
    puts new_data 
end 

def updated_list 
    puts "The newly added files are:-" 
    newly_added = new_data - old_data 
    puts newly_added 
end 

def deleted_list 
    puts "The deleted files are:-" 
    deleted_data = old_data - new_data 
    puts deleted_data 
end 

def stable_list 
    puts "The unchanged/stable files are:-" 
    unchanged_data = new_data - newly_added 
    puts unchanged_data 
end 
end#end of class 

while true 
    puts "Choose your option:" 
    puts "1.Old Files of System" 
    puts "2.New Files of System" 
    puts "3.Added Files of System" 
    puts "4.Deleted Files of System" 
    puts "5.Stable Lists" 
    puts "6.Exit" 
    print " Please Choose your Output:-" 
    **option_method=gets.chomp.to_i** 
    filecase1 = Differentiator.new 

    if option_method == 1 
    filecase1.old_stuff 
    end 

    if option_method == 2 
    filecase1.new_stuff 
    end 

    if option_method == 3 
    filecase1.updated_list 
    end 

    if option_method == 4 
    filecase1.deleted_list 
    end 

    if option_method == 5 
    filecase1.stable_list 
    end 

    if option_method == 6 
    break 
    exit 
    end 

    if option_method != (1..6) 
    puts "Sorry,Wrong Input" 
    end 
end 

else 
puts "The Right Method of Usage is : ruby <scriptname>.rb old_file new_file"; exit; 
end 

回答