Class: Lich::Common::Watchfor
- Inherits:
-
Object
- Object
- Lich::Common::Watchfor
- Defined in:
- documented/common/watchfor.rb
Overview
Represents a watcher for specific patterns in the script. This class allows you to define patterns to watch for and execute a block of code when those patterns are matched.
Class Method Summary collapse
-
.clear ⇒ void
rubocop:enable Lint/ReturnInVoidContext Clears all watch patterns from the current script.
Instance Method Summary collapse
-
#initialize(line, theproc = nil, &block) ⇒ nil
constructor
rubocop:disable Lint/ReturnInVoidContext Initializes a new Watchfor instance.
Constructor Details
#initialize(line, theproc = nil, &block) ⇒ nil
rubocop:disable Lint/ReturnInVoidContext Initializes a new Watchfor instance.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'documented/common/watchfor.rb', line 21 def initialize(line, theproc = nil, &block) return nil unless (script = Script.current) if line.is_a?(String) line = Regexp.new(Regexp.escape(line)) elsif !line.is_a?(Regexp) echo 'watchfor: no string or regexp given' return nil end if block.nil? if theproc.respond_to? :call block = theproc else echo 'watchfor: no block or proc given' return nil end end script.watchfor[line] = block end |