Class: IO
Class Method Summary collapse
-
.capture_stdout(&block) ⇒ Object
from output_catcher gem.
-
.read_until(file, string) ⇒ Object
Returns array of lines up until the given string matches a line of the file.
Class Method Details
.capture_stdout(&block) ⇒ Object
from output_catcher gem
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/core/io.rb', line 10 def self.capture_stdout(&block) original_stdout = $stdout $stdout = fake = StringIO.new begin yield ensure $stdout = original_stdout end fake.string end |
.read_until(file, string) ⇒ Object
Returns array of lines up until the given string matches a line of the file.
3 4 5 6 7 |
# File 'lib/core/io.rb', line 3 def self.read_until(file,string) f = self.readlines(file) i = f.index(string) || 100000 f.slice(0,i) end |