Class: Mux
- Inherits:
-
Object
- Object
- Mux
- Defined in:
- lib/mux.rb
Defined Under Namespace
Classes: Options
Class Method Summary collapse
Class Method Details
.open_streams(targets, type) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/mux.rb', line 59 def self.open_streams(targets, type) handles = [] targets.each do |target| case type when 'pipe' handles << IO.popen(target, 'w') when 'funnel' handles << File.open(target, 'w') when 'append' handles << File.open(target, 'a') end end handles end |
.run(args) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/mux.rb', line 34 def self.run(args) = Mux::Options.parse(args) streams = [] if .to_stdout streams << $stdout end streams.concat(open_streams(.pipes, 'pipe')) streams.concat(open_streams(.funnels, 'funnel')) streams.concat(open_streams(.appends, 'append')) while buffer = $stdin.gets streams.each do |stream| stream.puts buffer end end streams.each do |stream| stream.close end end |