Method: Main::Program::InstanceMethods#stdin=

Defined in:
lib/main/program/instance_methods.rb

#stdin=(io) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/main/program/instance_methods.rb', line 101

def stdin= io
  unless(defined?(@stdin) and (@stdin == io))
    @stdin =
      if io.respond_to?('read')
        io
      else
        fd = open(io.to_s, 'r+')
        finalizers.push(lambda{ fd.close })
        fd
      end
    begin
      STDIN.reopen(@stdin)
    rescue
      $stdin = @stdin
      ::Object.send(:remove_const, 'STDIN')
      ::Object.send(:const_set, 'STDIN', @stdin)
    end
  end
end