Search code examples
rubyruby-on-rails-3irbawesomeprint

How do you disable awesome_print once enabled in IRB or rails console?


I have awesome_print configured to be my default formatter in IRB (using AwesomePrint.irb! in my .irbrc) and while this is normally awesome, I want to turn it off sometimes. Anybody know how to from a running IRB/Rails console?


Solution

  • You can paste this in to you terminal to reset it back to what it was originally if you like:

    IRB::Irb.class_eval do
      def output_value # :nodoc:
        printf @context.return_format, @context.inspect_last_value
      end
    end
    

    or you can go whole hog and monkey patch AwesomePrint:

    module AwesomePrint
      def self.un_irb!
        IRB::Irb.class_eval do
          def output_value # :nodoc:
            printf @context.return_format, @context.inspect_last_value
          end
        end
      end
    end
    

    Then just call it whenever you want: AwesomePrint.un_irb!