How to run IRB.start in context of current class

后端 未结 8 981
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-29 21:23

I\'ve been just going through PragProg Continuous Testing With Ruby, where they talk about invoking IRB in context of current class to inspect the code

8条回答
  •  离开以前
    2020-12-29 22:21

    I'd suggest trying this in ripl, an irb alternative. The above example works:

    a = 'hello'
    require 'ripl'
    Ripl.start :binding => binding
    

    Note that local variables work because your passing the current binding with the :binding option.

    You could possibly do the same in irb, but since it's poorly documented and untested, your chances of doing it cleanly are slim to none.

提交回复
热议问题