Module: MyCore::IO::ClassMethods

Defined in:
lib/my_core/io.rb

Instance Method Summary collapse

Instance Method Details

#capture_stdout(&block) ⇒ Object

from output_catcher gem



12
13
14
15
16
17
18
19
20
21
# File 'lib/my_core/io.rb', line 12

def 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.



5
6
7
8
9
# File 'lib/my_core/io.rb', line 5

def read_until(file,string)
  f = readlines(file)
  i = f.index(string) || 100000
  f.slice(0,i)
end