How can I pass STDin to IRB without it exiting aft

2019-09-09 14:32发布

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条回答
孤傲高冷的网名
2楼-- · 2019-09-09 15:14

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
查看更多
登录 后发表回答