Class: IRB::Notifier::AbstractNotifier
Overview
An abstract class, or superclass, for CompositeNotifier and LeveledNotifier to inherit. It provides several wrapper methods for the OutputMethod object used by the Notifier.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
The
prefix
for this Notifier, which is appended to all objects being inspected during output.
Instance Method Summary collapse
-
#exec_if {|@base_notifier| ... } ⇒ Object
Execute the given block if notifications are enabled.
-
#initialize(prefix, base_notifier) ⇒ AbstractNotifier
constructor
Creates a new Notifier object.
-
#notify? ⇒ Boolean
A wrapper method used to determine whether notifications are enabled.
-
#pp(*objs) ⇒ Object
Same as #ppx, except it uses the #prefix given during object initialization.
-
#ppx(prefix, *objs) ⇒ Object
Same as #pp, except it concatenates the given
prefix
with the #prefix given during object initialization. -
#print(*opts) ⇒ Object
See OutputMethod#print for more detail.
-
#printf(format, *opts) ⇒ Object
See OutputMethod#printf for more detail.
-
#printn(*opts) ⇒ Object
See OutputMethod#printn for more detail.
-
#puts(*objs) ⇒ Object
See OutputMethod#puts for more detail.
Constructor Details
#initialize(prefix, base_notifier) ⇒ AbstractNotifier
Creates a new Notifier object
41 42 43 44 |
# File 'lib/irb/notifier.rb', line 41 def initialize(prefix, base_notifier) @prefix = prefix @base_notifier = base_notifier end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
The prefix
for this Notifier, which is appended to all objects being inspected during output.
48 49 50 |
# File 'lib/irb/notifier.rb', line 48 def prefix @prefix end |
Instance Method Details
#exec_if {|@base_notifier| ... } ⇒ Object
Execute the given block if notifications are enabled.
99 100 101 |
# File 'lib/irb/notifier.rb', line 99 def exec_if yield(@base_notifier) if notify? end |
#notify? ⇒ Boolean
A wrapper method used to determine whether notifications are enabled.
Defaults to true
.
53 54 55 |
# File 'lib/irb/notifier.rb', line 53 def notify? true end |
#pp(*objs) ⇒ Object
Same as #ppx, except it uses the #prefix given during object initialization. See OutputMethod#ppx for more detail.
82 83 84 85 86 |
# File 'lib/irb/notifier.rb', line 82 def pp(*objs) if notify? @base_notifier.ppx @prefix, *objs end end |
#ppx(prefix, *objs) ⇒ Object
Same as #pp, except it concatenates the given prefix
with the #prefix given during object initialization.
See OutputMethod#ppx for more detail.
92 93 94 95 96 |
# File 'lib/irb/notifier.rb', line 92 def ppx(prefix, *objs) if notify? @base_notifier.ppx @prefix+prefix, *objs end end |
#print(*opts) ⇒ Object
See OutputMethod#print for more detail.
58 59 60 |
# File 'lib/irb/notifier.rb', line 58 def print(*opts) @base_notifier.print prefix, *opts if notify? end |
#printf(format, *opts) ⇒ Object
See OutputMethod#printf for more detail.
68 69 70 |
# File 'lib/irb/notifier.rb', line 68 def printf(format, *opts) @base_notifier.printf(prefix + format, *opts) if notify? end |
#printn(*opts) ⇒ Object
See OutputMethod#printn for more detail.
63 64 65 |
# File 'lib/irb/notifier.rb', line 63 def printn(*opts) @base_notifier.printn prefix, *opts if notify? end |
#puts(*objs) ⇒ Object
See OutputMethod#puts for more detail.
73 74 75 76 77 |
# File 'lib/irb/notifier.rb', line 73 def puts(*objs) if notify? @base_notifier.puts(*objs.collect{|obj| prefix + obj.to_s}) end end |