为什么--simple-prompt命令不起作用?

时间:2015-07-07 00:17:17

标签: ruby irb

我刚开始使用Ruby,所以请耐心等待。问题是当我在OS 10.10.3终端上输入--simple-prompt到irb时,我没有得到简单的提示,我收到一条错误消息:

irb(main):001:0> --simple-prompt
NameError: undefined local variable or method `simple' for main:Object
    from (irb):1
    from /usr/local/bin/irb:11:in `<main>'

我假设以下问题与上述问题有关-v-cw等,似乎也不起作用。谢谢你的帮助!

2 个答案:

答案 0 :(得分:1)

您似乎对将标志传递给REPL中的命令与发布语句感到困惑。

要在启用irb选项的情况下启动--simple-prompt,请将其传递出去:

$ irb --simple-prompt
>>

然后你应该能够执行Ruby代码。

>> puts "hello world!"
hello world!
=> nil
>>

答案 1 :(得分:1)

问题是--simple-prompt是一个切换提示符的命令行选项。

您可以通过输入exit来退出IRB,然后输入

来查看

irb --help

这给你这样的东西:

Usage:  irb.rb [options] [programfile] [arguments]
  -f            Suppress read of ~/.irbrc
  -m            Bc mode (load mathn, fraction or matrix are available)
  -d                Set $DEBUG to true (same as `ruby -d')
  -r load-module    Same as `ruby -r'
  -I path           Specify $LOAD_PATH directory
  -U                Same as `ruby -U`
  -E enc            Same as `ruby -E`
  -w                Same as `ruby -w`
  -W[level=2]       Same as `ruby -W`
  --context-mode n  Set n[0-3] to method to create Binding Object,
                    when new workspace was created
  --echo            Show result(default)
  --noecho          Don't show result
  --inspect     Use `inspect' for output (default except for bc mode)
  --noinspect       Don't use inspect for output
  --readline        Use Readline extension module
  --noreadline      Don't use Readline extension module
  --prompt prompt-mode/--prompt-mode prompt-mode
            Switch prompt mode. Pre-defined prompt modes are
            `default', `simple', `xmp' and `inf-ruby'
  --inf-ruby-mode   Use prompt appropriate for inf-ruby-mode on emacs.
            Suppresses --readline.
  --sample-book-mode/--simple-prompt
                    Simple prompt mode
  --noprompt        No prompt mode
  --single-irb      Share self with sub-irb.
  --tracer          Display trace for each execution of commands.
  --back-trace-limit n
            Display backtrace top n and tail n. The default
            value is 16.
  --irb_debug n     Set internal debug level to n (not for popular use)
  --verbose         Show details
  --noverbose       Don't show details
  -v, --version     Print the version of irb
  -h, --help        Print help
  --                Separate options of irb from the list of command-line args

--sample-book-mode--simple-prompt用于这样的命令:

irb --simple-prompt

你也可以这样做:

irb --prompt simple

但是你不能在IRB里面做这些事情。

但是,有一种方法可以通过更改@prompt变量来更改IRB中的提示。