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

故事扮演 提交于 2019-11-30 17:31:16

问题


I can change the irb prompt mode with

irb --prompt prompt-mode

I can see what null and simple does, but I can't tell the difference between null and xmp and the difference between default/classic/inf-ruby. Can someone explain to me what these other modes do? It seems pointless to have multiple modes doing the same thing.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/2466680/whats-the-difference-between-the-ruby-irb-prompt-modes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!