How can I pass to IRB if I don't specify ?

前端 未结 3 1940
慢半拍i
慢半拍i 2021-02-05 22:47

Since:

irb --help

Usage: irb.rb [options] [programfile] [arguments]


I know I can pass arguments to ARGV if I include a prog

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-05 23:19

    You can make a file that modifies ARGV and then use '-r' to include it.

    $ echo 'ARGV = ["testing", "1","2","3"]' > ~/blah.rb && irb -r ./blah test.rb 
    /home/me/blah.rb:1: warning: already initialized constant ARGV
    test.rb(main):001:0> require 'pp'
    => true
    test.rb(main):002:0* pp ARGV
    ["testing", "1", "2", "3"]
    => ["testing", "1", "2", "3"]
    test.rb(main):003:0> 
    

    You could even redirect it to your your ~/.irbrc and leave out the '-r ./blah'.

提交回复
热议问题