2017-04-17 1 views
-2
class Datos 
    def initialize 
    end 
    def meteDatos 

sorry, wenn die Variablen in Spanisch, im aus Spanien und es ist einfacher für mich„nicht definierte Methode` jeder‘für‚datos.txt‘: String“

ich hoffe, dass niemand darüber Sorgen. ..

 print "escribe el nombre: " 
     $nombre = gets.chomp 
     print "escribe el apellido: " 
     $apellido = gets.chomp 
     print "escribe el dia de nacimiento: " 
     $dia = gets.chomp 
     print "escribe el mes de nacimiento: " 
     $mes = gets.chomp 
     print "escribe los dos primeros digitos de el ano de nacimiento: " 
     $ano1 = gets.chomp 
     print "escribe los dos ultimos digitos de el ano de nacimiento: " 
     $ano2 = gets.chomp 
     print "escribe el color favorito: " 
     $color = gets.chomp 
    end 
end 
datos = Datos.new() 
datos.meteDatos 
archivo = File.new("datos.txt","w+") 
archivo.puts $nombre 
archivo.puts $apellido 
archivo.puts $dia 
archivo.puts $mes 
archivo.puts $ano1 
archivo.puts $ano2 
archivo.puts $color 
archivo.close 

das Problem ist hier, und ich weiß Es ist im ‚.each‘ aber im diesen languaje lernen, und ich habe keine Ahnung, was los ist ...

begin 
File.open ("datos.txt").each {|i| puts i} 
gets() 
rescue => err 
    puts err.message 
end 
archivo.close 
File.delete("datos.txt") 
gets() 

Antwort

2

Zwischen File.open und ("datos.txt") liegt ein Leerzeichen. Entfernen Sie diesen Leerraum.

File.open ("datos.txt").each {...} (das Leerzeichen beachten) als File.open(("datos.txt").each {...})

interpretiert werden
Verwandte Themen