Class: Mux
- Inherits:
-
Object
- Object
- Mux
- Defined in:
- lib/mux.rb
Defined Under Namespace
Classes: Options
Constant Summary collapse
- M =
{ :pipe => {:class => 'IO', :method => 'popen', :mode => 'w'}, :funnel => {:class => 'File', :method => 'open', :mode => 'w'}, :append => {:class => 'File', :method => 'open', :mode => 'a'} }
Instance Method Summary collapse
Instance Method Details
#open_stream(target, type) ⇒ Object
63 64 65 |
# File 'lib/mux.rb', line 63 def open_stream(target, type) eval("#{M[type][:class]}.#{M[type][:method]}(target,'#{M[type][:mode]}')") end |
#open_streams(targets, type) ⇒ Object
59 60 61 |
# File 'lib/mux.rb', line 59 def open_streams(targets, type) targets.map {|t| open_stream(t,type) } end |
#run(args) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/mux.rb', line 39 def run(args) = Mux::Options.parse(args) streams = .to_stdout ? [$stdout] : [] # this is silly and rather non-intuitive (at least tonight), but is fun # nonetheless... i'll keep it around for a while and see what i think. # ps. IT TOTALLY WORKS! M.each_key do |k| o = lambda { eval("options.#{k}s") } streams.concat(open_streams(o.call, k)) if o.call end $stdin.each_line do |b| streams.each {|s| s.write b } end streams.each {|s| s.close } end |