From: onlynone@... Date: 2019-03-22T14:19:37+00:00 Subject: [ruby-core:91936] [Ruby trunk Bug#15371] IRB with ARGV Issue #15371 has been updated by onlynone (Steven Willis). svnpenn (Steven Penny) wrote: > shevegen (Robert A. Heiler) wrote: > > By the way, I find it slightly amusing that python's "there is only > > one way" became "there are four ways". ;-) > > Its actually only 2 ways if you want a true REPL: It's actually only 1 way. The `--` is just a command line option/argument parsing convention to mark an explicit break between options and arguments. It's useful when one of your arguments might look like an option. Like if you're trying to remove a file called `-i`, you can write `rm -- -i` and the `-i` will be treated as a filename argument and not the `-i` option to ask for confirmation before deletion. It's not a python thing. ---------------------------------------- Bug #15371: IRB with ARGV https://bugs.ruby-lang.org/issues/15371#change-77269 * Author: svnpenn (Steven Penny) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN ---------------------------------------- PHP allows you to pass ARGV in interactive mode: $ php -a -- alpha beta gamma php > print $argv[3] . PHP_EOL; gamma and Python offers 4 ways: $ python3 - alpha beta gamma >>> import sys >>> print(sys.argv[3]) gamma $ python3 -- - alpha beta gamma >>> import sys >>> print(sys.argv[3]) gamma $ python3 -i - alpha beta gamma >>> import sys >>> print(sys.argv[3]) gamma $ python3 -i -- - alpha beta gamma >>> import sys >>> print(sys.argv[3]) gamma However IRB seems to have no way to accomplish this: $ irb - alpha beta gamma /usr/share/ruby/2.3.0/irb/init.rb:213:in `parse_opts': Unrecognized switch: - (IRB::UnrecognizedSwitch) $ irb -- alpha beta gamma /usr/share/ruby/2.3.0/irb/magic-file.rb:8:in `initialize': No such file or directory @ rb_sysopen - alpha (Errno::ENOENT) $ irb -- - alpha beta gamma /usr/share/ruby/2.3.0/irb/magic-file.rb:8:in `initialize': No such file or directory @ rb_sysopen - - (Errno::ENOENT) $ irb - -- alpha beta gamma /usr/share/ruby/2.3.0/irb/init.rb:213:in `parse_opts': Unrecognized switch: - (IRB::UnrecognizedSwitch) -- https://bugs.ruby-lang.org/ Unsubscribe: