How to run IRB.start in context of current class

后端 未结 8 984
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-29 22:23

    Instead of global you could use instance variables, e.g.:

    require 'irb'
    @a = "hello"
    ARGV.clear
    IRB.start
    
    >> @a
    => "hello"
    

提交回复
热议问题