Reload rubygem in IRB

前端 未结 3 1033
轻奢々
轻奢々 2020-12-14 02:43

Is there a way to \"reload\" or \"refresh\" a rubygem in memory? As i\'m playing in irb, occasionally I like to modify my gem files, and if i require the same gem, it does n

3条回答
  •  一向
    一向 (楼主)
    2020-12-14 03:04

    One way is to use Kernel#load. You can use it pretty much like Kernel#require, except that you have to explicitly include the file extension. However, it has its drawbacks (even something as simple as class Foo < Struct.new(:foo); end fails, as it is not possible to change the superclass of an class), so I would also like to know a better way to do this.

    In rails you can achieve this with reload! on script/console, but I don't know what kind of magic they use.

    This gist looks promising but I haven't tested it.

提交回复
热议问题