在irb中重新加载rubygems? [英] Reload rubygems in irb?

查看:116
本文介绍了在irb中重新加载rubygems?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  def r(this)
需要这
放置#{this}现在被加载。
rescue LoadError
puts该宝石缺少#{this}'。
puts我应该安装它吗?[y / n]
data = gets
if data =〜/ yes | y / i
putsInstalling#{this},等一下。
如果`gem install#{this}`=〜/成功/ i
加载这个
结束
其他
提示Okey,再见。
end
end

这使得可以在运行时要求库。
像这样: rhaml



问题是我无法加载它已安装后的宝石。
使用加载这个加载File.expand_path(〜/ .irbrc)不起作用。



以下是一个例子。

 >> rabsolutize
宝石'absolutize'缺失。
我应该安装它吗? [y / n]
$
安装absolutize,按住
LoadError:不加载这样的文件 - absolutize
>>要求absolutize
LoadError:没有这样的文件加载 - absolutize
>>退出
$ irb
>>要求absolutize
=> true

有没有办法重新加载rubygems或irb?

解决方案

我没有尝试,但我想你可能正在寻找 Gem.clear_paths


重设目录和路径值。下一次请求目录或路径时,将从头开始计算值。这主要是由单元测试提供测试隔离。



I've this script right now.

def r(this)
  require this
  puts "#{this} is now loaded."
rescue LoadError
  puts "The gem '#{this}' is missing."
  puts "Should I install it? [y/n]"
  data = gets
  if data =~ /yes|y/i
    puts "Installing #{this}, hold on."
    if `gem install #{this}` =~ /Successfully/i
      load this
    end
  else
    puts "Okey, goodbye."
  end
end

That makes it possible to require libs on the fly. Like this: r "haml".

The problem is that I can't load the gem after it has been installed. Using load this or load File.expand_path("~/.irbrc") does not work.

Here is an example.

>> r "absolutize"
The gem 'absolutize' is missing.
Should I install it? [y/n]
y
Installing absolutize, hold on
LoadError: no such file to load -- absolutize
>> require "absolutize"
LoadError: no such file to load -- absolutize
>> exit
$ irb
>> require "absolutize"
=> true

Is there a way to reload rubygems or irb on the fly?

解决方案

I did not try, but I think you might be looking for Gem.clear_paths

Reset the dir and path values. The next time dir or path is requested, the values will be calculated from scratch. This is mainly used by the unit tests to provide test isolation.

这篇关于在irb中重新加载rubygems?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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