From: Bill Kelly Date: 2009-05-26T07:45:46+09:00 Subject: Re: Ruby Mulithreading From: "Hello There" > > What if i want the code to be able to run on linux aswell? gets doesn't block other threads on Linux, because select() isn't broken on Linux. So... one possibility would be to define a nonblocking gets method, which on Linux is just aliased to the original gets, since it works. But on windows, uses the nonblocking implementation. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if PLATFORM =~ /mswin/ def getsnb # do nonblocking gets using kbhit/getch as in previous email end else alias :getsnb :gets end # Example... x = getsnb ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Perhaps a cleaner approach would be to make a module which provides a replacement for gets on windows only. On non-windows systems, the module would be empty. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ module NonblockGets if PLATFORM =~ /mswin/ def gets # do nonblocking gets using kbhit/getch as in previous email end end end # Example.... class MyClass include NonblockGets def my_method x = gets # on windows, this will be the gets defined in NonblockGets module end end ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Hope this helps, Bill