lib/webgen/path.rb in gettalong-webgen-0.5.9.20090620 vs lib/webgen/path.rb in gettalong-webgen-0.5.9.20090626

- old
+ new

@@ -47,19 +47,24 @@ raise ArgumentError, 'You need to provide a block which returns an IO object' if @block.nil? end # Provide direct access to the wrapped IO object by yielding it. After the method block # returns the IO object is automatically closed. - def stream - io = @block.call + # + # The parameter +mode+ specifies the mode in which the wrapped IO object should be opened. + # This can be used, for example, to open a file in binary mode (or specify a certain input + # encoding under Ruby 1.9). + def stream(mode = 'r') + io = @block.call(mode) yield(io) ensure io.close end - # Return the whole content of the wrapped IO object as string. - def data - stream {|io| io.read} + # Return the whole content of the wrapped IO object as string. For a description of the + # parameter +mode+ see #stream. + def data(mode = 'r') + stream(mode) {|io| io.read} end end