Skip to content

Instantly share code, notes, and snippets.

@luizpicolo
Last active September 3, 2018 02:01
Show Gist options
  • Save luizpicolo/4674e27ac305c859d3c1056e98fca036 to your computer and use it in GitHub Desktop.
Save luizpicolo/4674e27ac305c859d3c1056e98fca036 to your computer and use it in GitHub Desktop.
def salvar_livro(livro_attrs = {})
File.open('livros', 'a') do |livro|
livro_attrs.each {|k, v| livro.puts "#{k}: #{v}" }
end
end
def condicional_para_saida(condicional)
return false if condicional == 2
return true
end
init = true
while init
livro_attrs = {}
puts 'Digite o titulo'
livro_attrs["Titulo"] = gets
puts 'Digite a categoria'
livro_attrs["Categoria"] = gets
puts 'Digite o autor'
livro_attrs["Autor"] = gets
puts 'Digite o isbn'
livro_attrs["Isbn"] = gets
salvar_livro(livro_attrs)
puts 'Deseja cadastrar mais? 2 para não'
condicional = gets.to_i
init = condicional_para_saida(condicional)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment