Skip to content

Instantly share code, notes, and snippets.

@abimaelmartell
Last active December 12, 2015 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save abimaelmartell/4759218 to your computer and use it in GitHub Desktop.
Save abimaelmartell/4759218 to your computer and use it in GitHub Desktop.
ejemplo de como iterar en un archivo
a = File.read './texto.txt'
b = a.scan(/inicio([\s\S]+?)fin/)
# un array para guardar los registros
c = []
b.each do |s|
# creo un hash para guardar los datos del registro actual
d = {}
# agrego cada uno de los campos
d[:edad] = s.to_s.scan(/edad (.+?)/)
# agrego el hash creado al arreglo
c.push d
end
# y ya tengo el arreglo con los datos c:
puts c.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment