How can I pass STDin to IRB without it exiting after processing this input?

依然范特西╮ 提交于 2019-12-13 06:06:36

问题


I'm using a short bash script to help me test an implementation of linked lists in ruby for class. I know about rspec and unit testing, and I'm certain they're better options for what I'm trying to do, but I was able to figure out this command

echo "require './nodes'" | irb

The output afterwards is

Switch to inspect mode.
require './nodes'
true

Technically a success, but the irb process ends there. So I tried

echo "require './nodes'" | irb --noinspect

Which gave me

Switch to non inspect mode.
require './nodes'
true

And it again exits the irb process.

I'm just trying to make my workflow a little bit more convenient, as I like to use irb to test my files by poking around at them and seeing what happens.


回答1:


Create a simple script, the code below will land you into the irb shell with the 'nodes' gem included. If you are using Ruby 1.8.x then you'll need to add require 'rubygems' before requiring nodes gem

#!/path/to/ruby -w

require 'irb'
require 'nodes'
IRB.start


来源:https://stackoverflow.com/questions/12776230/how-can-i-pass-stdin-to-irb-without-it-exiting-after-processing-this-input

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!