How do I drop to the IRB prompt from a running script?

后端 未结 6 622
再見小時候
再見小時候 2020-12-23 14:19

Can I drop to an IRB prompt from a running Ruby script?

I want to run a script, but then have it give me an IRB prompt at a point in the program with the current sta

6条回答
  •  情歌与酒
    2020-12-23 14:45

    Pry (an IRB alternative) also lets you do this, in fact it was designed from the ground up for exactly this use case :)

    It's as easy as putting binding.pry at the point you want to start the session:

    require 'pry'
    x = 10
    binding.pry
    

    And inside the session:

    pry(main)> puts x
    => 10
    

    Check out the website: http://pry.github.com

    Pry let's you:

    • drop into a session at any point in your code
    • view method source code
    • view method documentation (not using RI so you dont have to pre-generate it)
    • pop in and out of different contexts
    • syntax highlighting
    • gist integration
    • view and replay history
    • open editors to edit methods using edit obj.my_method syntax

    A tonne more great and original features

提交回复
热议问题