Tại đây, thêm cái này vào ~ / .irbrc của bạn:
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
(Lưu ý: Bạn phải cài đặt ctxgem trước, mặc dù tất nhiên awesome_printlà tùy chọn.)
Bây giờ khi bạn đang ở trên bất kỳ bảng điều khiển nào sử dụng irb, bạn có thể làm như sau:
Chế độ bình thường:
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"}}}
... vâng, đúng như những gì bạn mong đợi.
awesome_print chế độ:
irb(main):002:0> irb_mode(:ap)
irb#1(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 => [
        [0] {
            :will => "probably"
        },
        [1] {
            :be => "good to read"
        }
    ],
      :in => {
        :some => {
            :formatted => "way"
        }
    }
}
... wow, bây giờ mọi thứ đang in ra một cách đáng kinh ngạc! :)
Chế độ yên lặng:
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>
... whoah, không có đầu ra nào cả? Đẹp.
Dù sao, bạn có thể thêm bất kỳ chế độ nào bạn thích và khi bạn hoàn thành chế độ đó, chỉ cần exitthoát hoặc nó và bạn sẽ quay lại chế độ trước đó.
Hy vọng điều đó hữu ích! :)
     
              
users = User.all; 0