What's the difference between the ruby irb prompt modes?

后端 未结 2 765
无人共我
无人共我 2021-01-06 09:19

I can change the irb prompt mode with

irb --prompt prompt-mode

I can see what null and simple does, but I can\'t

相关标签:
2条回答
  • 2021-01-06 09:28

    The answer to those questions lie in IRB.conf[:PROMPT] which is a hash whose keys are the different prompts and whose values are the configurations for each prompt. Read this to a understand a prompt's configuration.

    The difference between null and xmp is that xmp displays a result indented with an arrow:

    $ irb --prompt xmp -f
    2**10
        ==>1024
    

    while null doesn't indent or display the arrow:

    $ irb --prompt null -f
    2**10
    1024
    

    You should be able to answer your second question once you read the above link and understand that prompts have different modes and different configurations for them.

    0 讨论(0)
  • 2021-01-06 09:31

    Once you read the article cldwalker posted above, you may want to design a custom prompt, here's mine for example:

    IRB.conf[:PROMPT][:CUSTOM] = {
      :PROMPT_I => ">> ",
      :PROMPT_S => "%l>> ",
      :PROMPT_C => ".. ",
      :PROMPT_N => ".. ",
      :RETURN => "=> %s\n"
    }
    IRB.conf[:PROMPT_MODE] = :CUSTOM
    IRB.conf[:AUTO_INDENT] = true
    
    0 讨论(0)
提交回复
热议问题