How do I get the “irb(main):001:0>” prompt instead of “>>”

混江龙づ霸主 提交于 2019-12-07 07:36:56

问题


Ruby is preinstalled on my Mac and so I wanted to have a look at it. First thing I noticed, is that irb prompts >> instead of irb(main):001:0>. I can't find anything on how to change this with Google because everyone is using irb(main):001:0> in their code ;-)

Can you help me out?

PS: It's not that I think Ruby is broken, but I want to look more nerdy while programming ;-)


回答1:


$ irb --help
Usage:  irb.rb [options] [programfile] [arguments]
  --prompt prompt-mode
  --prompt-mode prompt-mode
            Switch prompt mode. Pre-defined prompt modes are
            `default', `simple', `xmp' and `inf-ruby'

$ irb --prompt inf-ruby
irb(main):001:0> 



回答2:


What I do is make that into an alias in my .bashrc so I don't have to type it every time.

echo alias irb=\'irb --prompt inf-ruby\' >> ~/.bashrc

Hope this helps!




回答3:


goto the location /home/leapfrog/.rvm/scripts

cd ~/.rvm/scripts

Open the file ‘irbrc.rb’, use superuser power to over-write the

$ sudo gedit irbrc.rb

Change the content of the hash '@prompt' to the following

@prompt = {
 :PROMPT_I => "#{rvm_ruby_string} :%03n > ", # default prompt
 :PROMPT_S => "#{rvm_ruby_string} :%03n%l> ", # known continuation
 :PROMPT_C => "#{rvm_ruby_string} :%03n > ",
 :PROMPT_N => "#{rvm_ruby_string} :%03n?> ", # unknown continuation
 :RETURN => " => %s \n",
 :AUTO_INDENT => true
}

Hope this help you :)



来源:https://stackoverflow.com/questions/520099/how-do-i-get-the-irbmain0010-prompt-instead-of

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