Ruby:在一个项目中针对多个平台

发布于 2024-08-21 12:32:22 字数 1296 浏览 7 评论 0原文

我正在创建一个 [Iron]Ruby 项目,需要支持多种环境(更具体地说,WPF、Silverlight 和 WinForms - 但这并不那么重要)。以下是我陷入困境的实际具体示例:

我必须实现一个 Bitmap 类作为库的一部分,并且该类需要根据其运行的环境以不同的方式实现(例如,如果我在浏览器中将其作为 silverlight 应用程序运行,我将无法访问桌面上可用的方法)。问题是 - 我不控制 Bitmap 的实例化,也不控制库中任何其他类的实例化。为什么?因为它是另一个应用程序的端口;而且,虽然我确实有应用程序的代码,但我不想通过更改该代码来破坏兼容性。不过,我确实控制了应用程序的入口点,因此我可以require我需要的任何内容、执行设置、配置全局变量等。

编辑:< /strong> 如果你好奇,这是我正在从事的项目: http://github.com/cstrahan/open-rpg-maker

这是我的内容想知道:

  1. 我应该如何在启动时设置配置,以便 Bitmap 能够正常运行?
  2. 我应该如何在我的 git 存储库/源代码树中构建它?

以下是我的一些想法,但我相信您会有更好的想法:

  1. 我应该如何在启动时设置配置?
    • 分发应用程序时,根据目标环境在顶部放置 require,如下所示:require silverlight/bitmap。在这种情况下,lib/bitmap.rb 将为空,而 lib/silverlight/bitmap.rb 将包含实现。 或者...
    • 将所有实现填充到lib/bitmap.rb中,并根据类实例变量或常量有条件地执行:Bitmap.impl = "silverlight"或者...
    • 为每个发行版维护一个单独的分支 - 尽管库几乎完全相同。
  2. 我应该如何在我的 git 存储库/源代码树中构建它?
    • 每个发行版都有单独的分支。 或者...
    • 单独的特定于实现的子文件夹(例如lib/silverlight/bitmap.rb)。

作为 Ruby 的新手,我对此类最佳实践不太熟悉(我来自 C#)。任何建议将不胜感激!

——查尔斯

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:

  1. How should I set the configuration at startup, such that Bitmap will behave appropriately?
  2. 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:

  1. 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, while lib/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.
  2. 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文