本文介绍了为什么“要求rubygems”是错误的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据,要求rubygems是一个反模式。

  require'rubygems'





但是couldn'当你创建并与其他人共享代码库时,你需要的任何Ruby库都有相同的参数? 解决方案

需要使用rubygems的主要问题是,即使它们确实有实际需要的库,它也会在没有安装rubygems的系统上导致错误。



有些人在需要rubygems的时候通过解决LoadError来解决这个问题,但这很糟糕。


According to this post, requiring rubygems is an antipattern.

require 'rubygems'

The argument seems to boil down to this:

But couldn't the same argument be made about any Ruby library that you 'require' when you create and share a library of code with other people?

解决方案

The main problem with requiring rubygems is that it will cause an error on systems that do not have rubygems installed even if they do have the library that you actually want to require.

Some people work around that by rescuing LoadError when requiring rubygems, but that's kind of ugly.

这篇关于为什么“要求rubygems”是错误的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 10:49