Last active
December 12, 2015 10:29
-
-
Save abimaelmartell/4759218 to your computer and use it in GitHub Desktop.
ejemplo de como iterar en un archivo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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