Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
¿Qué significa .seek en Ruby?

¿Cuál es el propósito de f.seek(0) en este script? ¿Por qué necesitamos rewind(current_file) , si el programa ya abrió el archivo?

 input_file = ARGV[0] def print_all(f) puts f.read() end def rewind(f) f.seek(0) end def print_a_line(line_count,f) puts "#{line_count} #{f.readline()}" end current_file = File.open(input_file) puts "First Let's print the whole file:" puts # a blank line print_all(current_file) puts "Now Let's rewind, kind of like a tape" rewind(current_file) puts "Let's print the first line:" current_line = 1 print_a_line(current_line, current_file)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Busca ("va a", "intenta encontrar") una posición dada (como un número entero) en una secuencia. En su código, define un nuevo método llamado rewind que toma un argumento. Cuando lo llamas con

 rewind(current_file)

envía el archivo actual (el que ha abierto desde el disco o desde cualquier otro lugar) que se define como:

 current_file = File.open(input_file)

al método de rebobinado y "buscará" la posición 0, que es el comienzo del archivo.

También podrías crear otro método llamado almost_rewind y escribir:

 def almost_rewind(f) f.seek(-10, IO::SEEK_END) end

Esto iría 10 posiciones hacia atrás en su transmisión, comenzando desde el FIN de la transmisión.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!