How to suppress the output of return value in IRB/Rails Console?

后端 未结 4 1868
别那么骄傲
别那么骄傲 2020-12-23 20:29

An example is if I go into IRB and do the following:

jruby-1.6.7 :026 > puts [1,2,3,4,5]
1
2
3
4
5
=> nil 

Is there anyway to suppres

4条回答
  •  悲&欢浪女
    2020-12-23 21:21

    If you just want to suppress long output once in a while, use ;0, like:

    a = [*1..10000];0
    # => 0
    

    If you want to suppress it generally, use the ~/.irbrc file. The IRB.conf[:INSPECT_MODE] and IRB.conf[:PROMPT][your_prompt][:RETURN] control what is returned. You can figure out what your_prompt is by checking IRB.conf[:PROMPT_MODE]

    Example:

    IRB.conf[:PROMPT][:DEFAULT][:RETURN] = "" # suppress return value completely
    

    You'll need to restart irb after changing the value.

    Hope that helps.

提交回复
热议问题