I have a few ruby scripts that I use to make life a little easier at
work. Some of said scripts utilize the clipboard. Work is windows and
my laptop runs Ubuntu. I'm able to use the same scripts on both
computers but I have a few qualms with how I'm doing it.
Right now I've got classes for gnome and windows, a clipboard wrapper
class to be used by my scripts and a real basic OS class I use to
determine which class desktop class to use.
First off, the method I'm using to determine OS is...terrible.
Currently I'm doing a string comparison in my OS class, but it doesn't
actually tell me which desktop application I'm actually running, so at
the moment it's just a dirty hack but I'm not sure of the preferred
way to do it..
CODE
def is_linux
return RUBY_PLATFORM == 'i486-linux'
end
Second, I'm uncomfortable with how I'm importing my desktop specific
code in the main clipboard class. Is there a ruby-er way of doing
this, or maybe just a smarter way anyone knows of?
CODE
class Clipboard
def initialize
os = OS.new
if(os.is_linux)
require 'clipboard/clipboard_gtk'
clipboard = GTKClipboard.new
else
require 'clipboard/clipboard_win32'
clipboard = WinClipboard.new
end
#other stuff
end
Any help would be greatly appreciated!
Here's the code if anyone would like to take a gander:
http://joezack.com/downloads/code/ruby/clipboard.zip