Top Level Namespace
Defined Under Namespace
Instance Method Summary collapse
-
#openany(arg, &block) ⇒ Object
takes a filename or an io object, hands a rewinded io object to the reciever and then closes the file or places the io in the original position.
Instance Method Details
#openany(arg, &block) ⇒ Object
takes a filename or an io object, hands a rewinded io object to the reciever and then closes the file or places the io in the original position.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/openany.rb', line 5 def openany(arg, &block) io = if arg.is_a?(String) # filename File.open(arg) else orig_pos = arg.pos arg.rewind arg end reply = block.call(io) if arg.is_a?(String) # filename io.close else arg.pos = orig_pos end reply end |