Here add this to your ~ / .irbrc:
require 'ctx' require 'awesome_print' module IRB class Irb ctx :ap do def output_value() ap(@context.last_value) end end ctx :puts do def output_value() puts(@context.last_value) end end ctx :p do def output_value() p(@context.last_value) end end ctx :quiet do def output_value() end end end end def irb_mode(mode) ctx(mode) { irb } end
(Note: you must first set the ctx stone, although awesome_print is optional, of course.)
Now that you are on any console using irb, you can do the following:
Normal mode:
irb(main):001:0> { this:'is a complex object', that:[ { will:'probably'}, { be:'good to read' } ], in:{ some:{ formatted:'way'} } } => {:this=>"is a complex object", :that=>[{:will=>"probably"}, {:be=>"good to read"}], :in=>{:some=>{:formatted=>"way"}}}
... yep what are you expecting.
awesome_print :
irb(main):002:0> irb_mode(:ap) irb
... wow, now everything prints amazingly! :)
Quiet mode:
irb#1(main):002:0> irb_mode(:quiet) irb#1(main):001:0> { this:'is a complex object', that:[ { will:'probably'}, { be:'good to read' } ], in:{ some:{ formatted:'way'} } } irb#1(main):002:0>
... ahh, no conclusion at all? Nice.
In any case, you can add any mode that you like, and when you finish with this mode, just exit outside or it and you will return to the previous mode.
Hope this was helpful! :)
Mason Cloud Jun 08 '13 at 2:05 2013-06-08 02:05
source share