草庐IT

return-type-requirement

全部标签

ruby - 如何在 Ruby 中获取 `required` 的文件列表?

这纯粹是一个实验,但我想知道是否有可能通过某种元编程在运行时获取require的gem列表。例如,假设我有:require'rubygems'require'sinatra'require'nokogiri'#don'tknowwhattodohere如何在运行时打印出以下内容?thisappneedsrubygems,sinatra,nokogiri 最佳答案 您不能完全做到这一点,因为需要一个文件可能需要其他文件,而Ruby无法区分您需要的文件和其他人需要的文件。p>您可以查看$LOADED_FEATURES以获取所需的每一项内

ruby - "<top (required)>"在 Ruby 堆栈跟踪中意味着什么?

在Ruby1.9.2堆栈跟踪中,我经常看到给出的方法为,如下面的堆栈部分所示。这是什么意思?我的Ruby安装有什么问题吗?Couldnotfindabstract-1.0.0inanyofthesources/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:87:in`blockinmaterialize'/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:81:in`map!'/usr/l

ruby-on-rails - Rails 迁移 : tried to change the type of column from string to integer

我使用railsgeneratemigrations命令在我的rails应用程序中创建了一个表。这是迁移文件:classCreateListings然后我想将纬度和经度存储为整数我试着跑:railsgeneratemigrationchangeColumnType该文件的内容是:classChangeColumnType我原以为列类型会发生变化,但是rake被中止并出现了以下错误消息。我想知道为什么这没有通过?我在我的应用程序中使用postgresql。rakedb:migrate==ChangeColumnType:migrating=========================

ruby - RSpec allow/expect 与 just expect/and_return

在RSpec中,特别是版本>=3,有什么区别:使用allow设置带有返回测试替身的参数的消息期望,然后使用expect对返回的测试替身进行断言只需使用expect设置带有参数的期望并返回测试替身还是只是语义?我知道用expect提供/指定返回值是thesyntaxinRSpecmocks2.13,但据我所知,thesyntaxchangedinRSpecmocks3使用允许。但是,在下面的(传递的)示例代码中,使用allow/expect或仅使用expect/and_return似乎产生相同的结果。如果一种语法比另一种语法更受欢迎,也许我会期望有某种弃用通知,但由于没有,这两种语法似乎

ruby - 有 ruby 单行 "return if x"吗?

有很多地方需要补充ifthis_flagreturnend可以用ruby​​在一行中完成吗? 最佳答案 istherearubyone-line“returnifx”?是的:returnvalueifcondition我喜欢Ruby:-) 关于ruby-有ruby单行"returnifx"吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/5436034/

ruby-on-rails - OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server hello A

下面的代码会产生以下错误:OpenSSL::SSL::SSLError:SSL_connectSYSCALLreturned=5errno=0state=SSLv3readserverhelloArequire'net/https'uri=URI.parse("https://.com")http=Net::HTTP.new(uri.host,uri.port)http.use_ssl=truehttp.ssl_version='SSLv3'http.get(uri.request_uri)知道为什么吗?我尝试了所有其他问题中提到的所有内容,仍然没有运气。Ruby1.9.3p484(2

ruby - 在 Mac 10.7 上运行 'requirements_osx_brew_libs_install...' 时出错

尝试在上一代MacbookPro上安装brew并不断收到以下错误:Errorrunning'requirements_osx_brew_libs_installautoconfautomakelibtoolpkg-configapple-gcc42libyamlreadlinelibxml2libxsltlibksbaopensslsqlite',pleaseread/Users/allegrascrugham/.rvm/log/ruby-1.9.3-p392/1368142352_package_install_autoconf_automake_libtool_pkg-config

ruby - 安装 RVM : "Requirements installation failed with status: 1."

这是我在命令提示符之前看到的最后一件事:Searchingforbinaryrubies,thismighttakesometime.Foundremotefilehttps://rvm.io/binaries/osx/10.9/x86_64/ruby-2.1.1.tar.bz2Checkingrequirementsforosx.AbouttoinstallHomebrew,press`Enter`fordefaultinstallationin`/usr/local`,typenewpathifyouwishcustomHomebrewinstallation(thepathnee

ruby - Ruby 中的 class() 与 type()

Ruby中的类方法和类型方法有什么区别?我注意到type可以找到某些类的类型,但不能找到其他类的类型。 最佳答案 主要区别在于Object#type已弃用。来自对象#type的RDoc:DeprecatedsynonymforObject#class.这就是你应该使用Object#class的原因:Returnstheclassofobj,nowpreferredoverObject#type,asanobject‘stypeinRubyisonlylooselytiedtothatobject‘sclass.Thismethodm

ruby - 我如何从 `require' : no such file to load in ruby? 中拯救

我正在尝试从“require”中解救出来:没有这样的文件可以按顺序加载到ruby​​中提示用户指定-I标志,以防他忘记这样做。基本上代码如下所示:beginrequire'someFile.rb'rescueputs"someFile.rbwasnotfound,haveyou"puts"forgottentospecifythe-Iflag?"exitend我原以为rescue部分会在找不到someFile.rb的情况下接管执行,但我的假设是错误的。 最佳答案 没有参数的rescue只拯救StandardErrors。LoadEr