Hello, fellow Rubyists!
I am creating an [Iron]Ruby project that needs to support several environments (more specifically, WPF, Silverlight, and WinForms - but that's not as important). The following is an actual, concrete example of where I'm stuck:
I have to implement a Bitmap
class as part of a library, and this class will need to be implemented differently depending on what environment it's running in (e.g. if I'm running this in the browser as a silverlight app, I won't have access to methods that would be available on the desktop). And here's the catch - I don't control the instantiation of Bitmap
, nor any of the other classes within the library. Why? Because it's a port of another application; and, while I do have the code for the application, I don't want to break compatibility by changing that code. I do, however, control the entry point to the application, so I can require
whatever I need, perform setup, configure global variables, etc.
Edit: If you're curious, this is the project I'm working on: http://github.com/cstrahan/open-rpg-maker
Here's what I want to know:
- How should I set the configuration at startup, such that Bitmap will behave appropriately?
- How should I structure this in my git repo / source tree?
Here are some of my thoughts, but I'm sure you'll have better ideas:
- How should I set the configuration at startup?
- When distributing the app, place a
require
at the top depending on the targeted environment, like so:require silverlight/bitmap
. In this case,lib/bitmap.rb
would be empty, whilelib/silverlight/bitmap.rb
would contain the implementation. Or... - Stuff all implementations in
lib/bitmap.rb
, and conditionally execute based on a class instance variable or constant:Bitmap.impl = "silverlight"
. Or... - Maintain a separate branch for each distro - despite the library being almost exactly the same.
- When distributing the app, place a
- How should I structure this in my git repo / source tree?
- Separate branches per distribution. Or...
- Separate implementation-specific subfolders (e.g.
lib/silverlight/bitmap.rb
).
Being very new to Ruby, I'm not very familiar with such best practices (I'm coming from C#). Any advice would be greatly appreciated!
-Charles