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
43 44 45 46 |
# File 'lib/irb/notifier.rb', line 43 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.
50 51 52 |
# File 'lib/irb/notifier.rb', line 50 def prefix @prefix end |
Instance Method Details
#exec_if {|@base_notifier| ... } ⇒ Object
Execute the given block if notifications are enabled.
101 102 103 |
# File 'lib/irb/notifier.rb', line 101 def exec_if yield(@base_notifier) if notify? end |
#notify? ⇒ Boolean
A wrapper method used to determine whether notifications are enabled.
Defaults to true
.
55 56 57 |
# File 'lib/irb/notifier.rb', line 55 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.
84 85 86 87 88 |
# File 'lib/irb/notifier.rb', line 84 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.
94 95 96 97 98 |
# File 'lib/irb/notifier.rb', line 94 def ppx(prefix, *objs) if notify? @base_notifier.ppx @prefix+prefix, *objs end end |
#print(*opts) ⇒ Object
See OutputMethod#print for more detail.
60 61 62 |
# File 'lib/irb/notifier.rb', line 60 def print(*opts) @base_notifier.print prefix, *opts if notify? end |
#printf(format, *opts) ⇒ Object
See OutputMethod#printf for more detail.
70 71 72 |
# File 'lib/irb/notifier.rb', line 70 def printf(format, *opts) @base_notifier.printf(prefix + format, *opts) if notify? end |
#printn(*opts) ⇒ Object
See OutputMethod#printn for more detail.
65 66 67 |
# File 'lib/irb/notifier.rb', line 65 def printn(*opts) @base_notifier.printn prefix, *opts if notify? end |
#puts(*objs) ⇒ Object
See OutputMethod#puts for more detail.
75 76 77 78 79 |
# File 'lib/irb/notifier.rb', line 75 def puts(*objs) if notify? @base_notifier.puts(*objs.collect{|obj| prefix + obj.to_s}) end end |