Hello,
Here’s a code snippet. What it actually does?
def rewind(f)
f.seek(0, IO::SEEK_SET)
end
It’s from here : http://ruby.learncodethehardway.org/book/ex20.html
Any help would be appreciated.
Peace be upon you –
Junayeed Ahnaf Nirjhor
Twitter - @Nirjhor <http://twitter.com/nirjhor>
The parameter f is assumed to be an IO object of some kind. Those
objects include a method named seek that allows you to move the file
pointer for the IO object around without performing read or write
operations in order to do it.
In case you don't know what a file pointer is, it is the location in a
file's data from which read or write operations will start. When the
file pointer is 0, it is at the beginning of the file's data.
The rewind method above is setting the file pointer using an absolute
position of 0. The IO::SEEK_SET argument to the seek method is what
tells seek that the first argument of 0 is absolute.
For more information, see the documentation for IO#seek:
http://rdoc.info/stdlib/core/1.9.2/IO:seek
-Jeremy
···
On 10/14/2011 12:15, Junayeed Ahnaf Nirjhor wrote:
Hello,
Here’s a code snippet. What it actually does?
def rewind(f)
f.seek(0, IO::SEEK_SET)
end
Jeremy already gave you that answer, but I'll help you find many more yourself.
When trying to figure out what something does, a great way to find out
is to Google together as many of the significant words as you can. In
this case, if you Google seek and IO::SEEK_SET, the very first hit is
Learn How to Blog and Build Websites for Profit! which
explains all about reading and writing text files -- in Ruby. If you
omit the IO part, you wind up first with hits about other languages --
but at least you would probably be able to figure out the general idea
of what Ruby's "seek" *probably* does.
(And even that's without including Ruby as a search term. Googling
seek, SEEK_SET, *and Ruby*, gets you Satish's site again.)
Google-Fu is a very important skill to develop....
-Dave
···
On Fri, Oct 14, 2011 at 13:15, Junayeed Ahnaf Nirjhor <zombiegenerator@aol.com> wrote:
Here’s a code snippet. What it actually does?
def rewind(f)
f.seek(0, IO::SEEK_SET)
end
--
LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern languages.
Where: Northern Virginia, Washington DC (near Orange Line), and remote work.
davearonson.com (main) * codosaur.us (programing) * dare2xl.com (excellence)
Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (Aronson)