module AwesomePrint

Copyright © 2010-2016 Michael Dvorkin and contributors

Awesome Print is freely distributable under the terms of MIT license. See LICENSE file or www.opensource.org/licenses/mit-license.php

Copyright © 2010-2016 Michael Dvorkin and contributors

Awesome Print is freely distributable under the terms of MIT license. See LICENSE file or www.opensource.org/licenses/mit-license.php

Copyright © 2010-2016 Michael Dvorkin and contributors

Awesome Print is freely distributable under the terms of MIT license. See LICENSE file or www.opensource.org/licenses/mit-license.php

Copyright © 2010-2016 Michael Dvorkin and contributors

Awesome Print is freely distributable under the terms of MIT license. See LICENSE file or www.opensource.org/licenses/mit-license.php

Copyright © 2010-2016 Michael Dvorkin and contributors

Awesome Print is freely distributable under the terms of MIT license. See LICENSE file or www.opensource.org/licenses/mit-license.php

Copyright © 2010-2016 Michael Dvorkin and contributors

Awesome Print is freely distributable under the terms of MIT license. See LICENSE file or www.opensource.org/licenses/mit-license.php

Copyright © 2010-2016 Michael Dvorkin and contributors

Awesome Print is freely distributable under the terms of MIT license. See LICENSE file or www.opensource.org/licenses/mit-license.php

Copyright © 2010-2016 Michael Dvorkin and contributors

Awesome Print is freely distributable under the terms of MIT license. See LICENSE file or www.opensource.org/licenses/mit-license.php

Copyright © 2010-2016 Michael Dvorkin and contributors

Awesome Print is freely distributable under the terms of MIT license. See LICENSE file or www.opensource.org/licenses/mit-license.php

Copyright © 2010-2016 Michael Dvorkin and contributors

Awesome Print is freely distributable under the terms of MIT license. See LICENSE file or www.opensource.org/licenses/mit-license.php

Copyright © 2010-2016 Michael Dvorkin and contributors

Awesome Print is freely distributable under the terms of MIT license. See LICENSE file or www.opensource.org/licenses/mit-license.php

Copyright © 2010-2016 Michael Dvorkin and contributors

Awesome Print is freely distributable under the terms of MIT license. See LICENSE file or www.opensource.org/licenses/mit-license.php

Attributes

defaults[RW]
force_colors[RW]

Public Class Methods

console?() click to toggle source
# File lib/awesome_print/custom_defaults.rb, line 12
def console?
  boolean(defined?(IRB) || defined?(Pry))
end
diet_rb() click to toggle source
# File lib/awesome_print/custom_defaults.rb, line 20
def diet_rb
  IRB.formatter = Class.new(IRB::Formatter) do
    def inspect_object(object)
      object.ai
    end
  end.new
end
force_colors!(value = true) click to toggle source

Class accessor to force colorized output (ex. forked subprocess where TERM might be dumb).

# File lib/awesome_print/custom_defaults.rb, line 8
def force_colors!(value = true)
  @force_colors = value
end
inspect_object(object) click to toggle source
# File lib/awesome_print/custom_defaults.rb, line 22
def inspect_object(object)
  object.ai
end
irb!() click to toggle source
# File lib/awesome_print/custom_defaults.rb, line 38
def irb!
  return unless defined?(IRB)

  IRB.version.include?('DietRB') ? diet_rb : usual_rb
end
output_value(*args) click to toggle source
# File lib/awesome_print/custom_defaults.rb, line 30
def output_value(*args)
  ap @context.last_value
rescue NoMethodError
  puts "(Object doesn't support #ai)"
end
pry!() click to toggle source
# File lib/awesome_print/custom_defaults.rb, line 44
def pry!
  Pry.print = proc { |output, value| output.puts value.ai } if defined?(Pry)
end
rails_console?() click to toggle source
# File lib/awesome_print/custom_defaults.rb, line 16
def rails_console?
  console? && boolean(defined?(Rails::Console) || ENV['RAILS_ENV'])
end
usual_rb() click to toggle source
# File lib/awesome_print/custom_defaults.rb, line 28
def usual_rb
  IRB::Irb.class_eval do
    def output_value(*args)
      ap @context.last_value
    rescue NoMethodError
      puts "(Object doesn't support #ai)"
    end
  end
end
version() click to toggle source
# File lib/awesome_print/version.rb, line 7
def self.version
  '1.9.2'
end

Private Class Methods

boolean(value) click to toggle source

Takes a value and returns true unless it is false or nil This is an alternative to the less readable !!(value) github.com/bbatsov/ruby-style-guide#no-bang-bang

# File lib/awesome_print/custom_defaults.rb, line 53
def boolean(value)
  value ? true : false
end