Class: IO

Inherits:
Object
  • Object
show all
Defined in:
lib/io/bookmark.rb

Instance Method Summary collapse

Instance Method Details

#bookmark(rewind = false, &block) ⇒ Object

saves the position and returns to it after the block is executed. Returns the block’s reply. if rewind, io.rewind is called before handing the io object to the block.



6
7
8
9
10
11
12
# File 'lib/io/bookmark.rb', line 6

def bookmark(rewind=false, &block)
  start = self.pos
  self.rewind if rewind
  reply = block.call(self) 
  self.pos = start
  reply
end