123456789_123456789_123456789_123456789_123456789_

Class: IRB::Notifier::AbstractNotifier

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
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 ::IRB::OutputMethod object used by the ::IRB::Notifier.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(prefix, base_notifier) ⇒ AbstractNotifier

Creates a new ::IRB::Notifier object

[ GitHub ]

  
# File 'lib/irb/notifier.rb', line 41

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

Instance Attribute Details

#notify?Boolean (readonly)

A wrapper method used to determine whether notifications are enabled.

Defaults to true.

[ GitHub ]

  
# File 'lib/irb/notifier.rb', line 53

def notify?
  true
end

#prefix (readonly)

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

[ GitHub ]

  
# File 'lib/irb/notifier.rb', line 48

attr_reader :prefix

Instance Method Details

#exec_if {|@base_notifier| ... }

Execute the given block if notifications are enabled.

Yields:

  • (@base_notifier)
[ GitHub ]

  
# File 'lib/irb/notifier.rb', line 99

def exec_if
  yield(@base_notifier) if notify?
end

#pp(*objs)

Same as #ppx, except it uses the #prefix given during object initialization. See OutputMethod#ppx for more detail.

[ GitHub ]

  
# File 'lib/irb/notifier.rb', line 82

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

#ppx(prefix, *objs)

Same as #pp, except it concatenates the given #prefix with the #prefix given during object initialization.

See OutputMethod#ppx for more detail.

[ GitHub ]

  
# File 'lib/irb/notifier.rb', line 92

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

#printf(format, *opts)

See OutputMethod#printf for more detail.

[ GitHub ]

  
# File 'lib/irb/notifier.rb', line 68

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

#printn(*opts)

See OutputMethod#printn for more detail.

[ GitHub ]

  
# File 'lib/irb/notifier.rb', line 63

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

#puts(*objs)

See OutputMethod#puts for more detail.

[ GitHub ]

  
# File 'lib/irb/notifier.rb', line 73

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