Class: IO

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

Overview

Monkey-patches to Ruby's built-in IO class.

Instance Method Summary collapse

Instance Method Details

#to_list(sep = $/) ⇒ List

Return a lazy list of "records" read from this IO stream. "Records" are delimited by $/, the global input record separator string. By default, it is "\n", a newline.

Returns:

  • (List)


11
12
13
14
15
16
17
18
19
20
# File 'lib/hamster/core_ext/io.rb', line 11

def to_list(sep = $/) # global input record separator
  Hamster::LazyList.new do
    line = gets(sep)
    if line
      Hamster::Cons.new(line, to_list)
    else
      EmptyList
    end
  end
end