This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Kernel | |
def ai(options = {}) | |
ap = AwesomePrint::Inspector.new(options) | |
awesome = ap.awesome self | |
if options[:html] | |
awesome = "<pre>#{awesome}</pre>" | |
awesome = awesome.html_safe if defined? ActiveSupport | |
end | |
awesome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def format(object, type = nil) | |
core_class = cast(object, type) | |
awesome = if core_class != :self | |
send(:"awesome_#{core_class}", object) # Core formatters. | |
else | |
awesome_self(object, type) # Catch all that falls back to object.inspect. | |
end | |
awesome | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IRB::Irb.class_eval do | |
def output_value | |
puts 'cow' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module IRB | |
class Irb | |
def output_value | |
puts 'cow' | |
end | |
end | |
end | |
'dog' | |
=> cow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/awesome_print/inspector.rb (26) | |
def irb! | |
return unless defined?(IRB) | |
unless IRB.version.include?("DietRB") | |
IRB::Irb.class_eval do | |
def output_value | |
ap @context.last_value | |
end | |
end | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class C | |
@color1 = 'red' | |
puts @color1 | |
end | |
=> red | |
=> nil | |
class C | |
@color2 = 'blue' | |
puts @color1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# case 1 | |
class B | |
def method1 | |
1 | |
end | |
end | |
# case 2 | |
class B | |
def method2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A | |
@color = 'red' | |
puts @color | |
end | |
=> red | |
=> nil | |
class A | |
@color = 'blue' | |
puts @color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1, 2, 3].to_s | |
=> "[1, 2, 3, 4]" | |
class Array | |
def to_s | |
'[]' | |
end | |
end | |
[1, 2, 3].to_s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "prawn" | |
@pdf = Prawn::Document.new(margin: 0) | |
@text = "Oh hai text rect. " * 10 | |
@options = { :document => @pdf } | |
text_box = Prawn::Text::Box.new(@text, @options) | |
p "cursor before dry run: #{@pdf.cursor}" | |
p "whats the height before dry run?" | |
p "....who knows????" if text_box.height == 0 |
NewerOlder