For a clean solution, gem install hirb. hirb pages irb's returned values if they get too long.
If you want to monkeypatch irb:
module IRB
class Irb
def output_value
@context.last_value.to_s.slice(0, MAX_LEN)
end
end
end
Run Code Online (Sandbox Code Playgroud)
I don't recommend this because it's a hack and breaks any time gems like ap and hirb are required.
Instead of monkeypatching irb, I'd recommend trying ripl, an irb alternative that is meant to extended. The above as a ripl plugin would be:
require 'ripl'
module Ripl::SlicedInspect
def format_result(result)
result_prompt + result.inspect.slice(MAX_LEN)
end
end
Ripl::Shell.send :include, Ripl::SlicedInspect
Run Code Online (Sandbox Code Playgroud)
With this plugin, you could require it as needed or add to your ~/.riplrc if you want to always use it.
| 归档时间: |
|
| 查看次数: |
804 次 |
| 最近记录: |