Class: IRB::Notifier::AbstractNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/irb/notifier.rb

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

CompositeNotifier, LeveledNotifier

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix, base_notifier) ⇒ AbstractNotifier

Creates a new Notifier object


42
43
44
45
# File 'lib/irb/notifier.rb', line 42

def initialize(prefix, base_notifier)
	@prefix = prefix
	@base_notifier = base_notifier
end

Instance Attribute Details

#prefixObject (readonly)

The prefix for this Notifier, which is appended to all objects being inspected during output.


49
50
51
# File 'lib/irb/notifier.rb', line 49

def prefix
  @prefix
end

Instance Method Details

#exec_if {|@base_notifier| ... } ⇒ Object

Execute the given block if notifications are enabled.

Yields:

  • (@base_notifier)

100
101
102
# File 'lib/irb/notifier.rb', line 100

def exec_if
	yield(@base_notifier) if notify?
end

#notify?Boolean

A wrapper method used to determine whether notifications are enabled.

Defaults to true.

Returns:

  • (Boolean)

54
55
56
# File 'lib/irb/notifier.rb', line 54

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.


83
84
85
86
87
# File 'lib/irb/notifier.rb', line 83

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.


93
94
95
96
97
# File 'lib/irb/notifier.rb', line 93

def ppx(prefix, *objs)
	if notify?
	  @base_notifier.ppx @prefix+prefix, *objs
	end
end

See OutputMethod#print for more detail.


59
60
61
# File 'lib/irb/notifier.rb', line 59

def print(*opts)
	@base_notifier.print prefix, *opts if notify?
end

#printf(format, *opts) ⇒ Object

See OutputMethod#printf for more detail.


69
70
71
# File 'lib/irb/notifier.rb', line 69

def printf(format, *opts)
	@base_notifier.printf(prefix + format, *opts) if notify?
end

#printn(*opts) ⇒ Object

See OutputMethod#printn for more detail.


64
65
66
# File 'lib/irb/notifier.rb', line 64

def printn(*opts)
	@base_notifier.printn prefix, *opts if notify?
end

#puts(*objs) ⇒ Object

See OutputMethod#puts for more detail.


74
75
76
77
78
# File 'lib/irb/notifier.rb', line 74

def puts(*objs)
	if notify?
	  @base_notifier.puts(*objs.collect{|obj| prefix + obj.to_s})
	end
end