Is it possible to change the width that prettyprint (require \'pp\'
) uses when formatting output? For example:
\"mooth\"=>[\"booth\", \"month\",
#!/usr/bin/ruby1.8
require 'pp'
mooth = [
"booth", "month", "mooch", "morth",
"mouth", "mowth", "sooth", "tooth"
]
PP.pp(mooth, $>, 40)
# => ["booth",
# => "month",
# => "mooch",
# => "morth",
# => "mouth",
# => "mowth",
# => "sooth",
# => "tooth"]
PP.pp(mooth, $>, 79)
# => ["booth", "month", "mooch", "morth", "mouth", "mowth", "sooth", "tooth"]
To change the default with a monkey patch:
#!/usr/bin/ruby1.8
require 'pp'
class PP
class << self
alias_method :old_pp, :pp
def pp(obj, out = $>, width = 40)
old_pp(obj, out, width)
end
end
end
mooth = ["booth", "month", "mooch", "morth", "mouth", "mowth", "sooth", "tooth"]
pp(mooth)
# => ["booth",
# => "month",
# => "mooch",
# => "morth",
# => "mouth",
# => "mowth",
# => "sooth",
# => "tooth"]
These methods also work in MRI 1.9.3