Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,299 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,455 people online right now. Registration is fast and FREE... Join Now!




Coding for different platforms

 
Reply to this topicStart new topic

Coding for different platforms

Skinnyarms
2 Sep, 2008 - 06:14 PM
Post #1

New D.I.C Head
*

Joined: 18 Nov, 2006
Posts: 31


My Contributions
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
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 06:12AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month