Fügen Sie dies hier zu Ihrem ~ / .irbrc hinzu:
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
(Hinweis: Sie müssen den ctxEdelstein zuerst installieren , dies awesome_printist jedoch natürlich optional.)
Wenn Sie sich jetzt auf einer Konsole befinden, die irb verwendet, können Sie Folgendes tun:
Normaler Modus:
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"}}}
... ja, genau das, was Sie erwarten.
awesome_print Modus:
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, jetzt wird alles großartig ausgedruckt! :) :)
Ruhemodus:
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, überhaupt keine Ausgabe? Nett.
Wie auch immer, Sie können einen beliebigen Modus hinzufügen. Wenn Sie mit diesem Modus fertig sind, können exitSie ihn einfach wieder ausschalten.
Hoffe das war hilfreich! :) :)
users = User.all; 0