2013-05-29 173 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 

回答