From: Joe Van Dyk Date: 2006-03-09T06:18:02+09:00 Subject: idioms for separating out OS-specific stuff I have a few functions that: - get the current user's login name - checks to see what the CPU % of a process is (non the Ruby process, another process). This includes all the threads that the process has - forks a new process - sees if a process is still running - gets the utilization percentage of a NIC on the machine - the load average of the machine - the number of CPUs on a given machine This is all working fine on Linux with kernel 2.4. However, the code doesn't quite run correctly on a 2.6 kernel (not sure why yet). And forget about OS X and Windows and *BSD. Are there any good Ruby idioms for managing the separate OS-specific functions? My first thought: module SystemSpecificMethods module Linux # generic linux functions in here module 2.4 # linux 2.4 functions in here end module 2.6 # linux 2.6 functions in here end end module Windows # Windows functions here end module BSD # OS X and maybe *BSD functions here end end And then probe (somwhow?) to figure out what OS I'm running on and then including the correct modules into my code. So, if I were using Linux 2.6, I'd include SystemSpecificFunctions::Linux and SystemSpecificFunctions::Linux::2.6. But I'm sure that's a pretty dumb way of doing it, as I'm not terribly bright. Joe