Silence output of return object in IRB console on windows

Notice: This is supposed to work for Rails console too. But somehow it only works for IRB console.

Let's see some examples first:

When it output return object:


When it doesn't output return object:



Why sometimes we may want to disable outputting return object?

Take my case as an example, I have a huge array, I want to loop through this array and print out some elements that accords with a certain criteria. With output return object enabled, it will print the elements, then output the whole array. Since the array is huge, even though I increase my console buffer to maximum, scroll to top, I still couldn't see the beginning of the array, not even mention the element output.


How to disable?

Create .irbrc file in %HOME% directory(For ex, mine is "C:\Users\yatwang". And add these lines in the file:

IRB.conf[:PROMPT][:NO_RETURN] = {
  PROMPT_I: "%N(%m):%03n:%i> ",
  PROMPT_S: "%N(%m):%03n:%i%l ",
  PROMPT_C: "%N(%m):%03n:%i* ",
  RETURN: "" # used to printf
}
IRB.conf[:PROMPT_MODE] = :NO_RETURN

An alternative: you can create a file with the same content. You can name it whatever you want, or put it anywhere you want. Just need to add a system environment variable "IRBRC", whose value points to the location of the file.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值