Joel VanderWerf wrote:
Kyle S. wrote:
OK, this is probably a very basic question, but how do ou go about
lowering the verbosity of irb?
You can set up irb to limit the number of chars it prints. Put the
following code in your .irbrc. This was originally written by Stian H…
I hadn’t looked at that code in a long time. The following is cleaned up
a bit, and with a sample output at the end (you can see how it guesses
that the last char is a delimiter of some kind).
class IRB::Context
attr_accessor :max_output_size
alias initialize_before_max_output_size initialize
def initialize(*args)
initialize_before_max_output_size(*args)
@max_output_size = IRB.conf[:MAX_OUTPUT_SIZE] || 500
end
end
class IRB::Irb
def output_value
text =
if @context.inspect?
sprintf @context.return_format, @context.last_value.inspect
else
sprintf @context.return_format, @context.last_value
end
max = @context.max_output_size
if text.size < max
puts text
else
puts text[0…max-1] + “…” + text[-2…-1]
end
end
end
END
irb(main):001:0> (1…1000).to_a
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
121,…]