我可以在Opal中使用Ruby宝石吗? [英] Can I use Ruby gems in Opal?

查看:113
本文介绍了我可以在Opal中使用Ruby宝石吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

opal-irb 和 opal-jquery 维也纳 $ c> lib 通过使用 Opal.use_gem



缺陷是:


  • 使用String可变性

  • 依赖于String和Symbol之间的区别
  • li>
  • 炮击(``%x {}



修复/解决其中一些问题的可用工具包括:


  • 删除文件 Opal :: Processor.stub_file('fileutils')

  • 在编译时使用<$ c隐藏代码分支$ c> RUBY_ENGINE ,
    例如:

    除非RUBY_ENGINE =='opal'
    unparsable / break代码





    你可以看看 opal- rspec的源代码来查看这个行为:



    https:// github .com / opal / opal-rspec


    There's opal-irb and opal-jquery and vienna but is there any way to use gems directly in the browser via Opal?

    解决方案

    You can add a gem's lib path to Opal load paths by using Opal.use_gem

    Common pitfalls are:

    • use of String mutability
    • relying on the difference between String and Symbol
    • shelling out (`` and %x{})

    Available tools to fix/workaround some of those issues are:

    • stubbing files Opal::Processor.stub_file('fileutils')
    • hiding code branches at compile time using RUBY_ENGINE, example: unless RUBY_ENGINE == 'opal' unparsable/breaking code here end

    You can look at the opal-rspec source code to see this stuff in action:

    https://github.com/opal/opal-rspec

    这篇关于我可以在Opal中使用Ruby宝石吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆