0
CSV 및 루비에 대한 경험이있는 사람이 누구나 있습니다. 나는 그것에 새롭고 사용자가 입력 한 이름과 암호를 저장하기 위해 csv 파일을 사용하는 프로그램을 만들려고 노력하고 있습니다. 나는 다른 여러 게시물을 읽고 내 자신의 일부에 던져. 그러나 남아있는 코드의 일부는 배열에 grep 메서드를 가지고 있습니다. 비슷한 방법으로 대체 메서드가 있는지 알고 싶습니다. 이제는 csv에서 이름을 검색 한 다음 해당 비밀번호와 일치하는지 확인한 다음 비밀번호가 일치하면 비밀번호를 확인하여 추가로 액세스 할 수있게해야합니다.루비 CSV IO 상호 작용
는def enter_the_vault(path_to_csv)
@names = []
csv_contents = CSV.read(path_to_csv)
csv_contents.shift
csv_contents.each do |row|
@names << row[0]
end
@names.each {|f| f.downcase! }
end
def search_for_user
puts "Please enter your username: "
usern = gets.chomp.downcase
results = [@names.grep(/#{usern}/)]
if results.each {|f| puts f}
prompt
else
puts "user does not exist"
prompt
end
end
def prompt
puts "Incorrect.. do you want to retry: (y/n)"
answer = gets.chomp.downcase
case answer
when /^y/
search_for_user
when /^n/
puts "Goodbye."
exit
else
prompt
end
end
감사합니다. 나는 완전히 다른 모습을 보입니다. – TheLegend