Class: Lich::Common::Watchfor
- Inherits:
-
Object
- Object
- Lich::Common::Watchfor
- Defined in:
- documented/common/watchfor.rb
Overview
Represents a watcher that triggers a block of code when a specified line matches a pattern.
Instance Method Summary collapse
-
#initialize(line, theproc = nil) { ... } ⇒ void
constructor
rubocop:disable Lint/ReturnInVoidContext Initializes a new Watchfor instance.
Constructor Details
#initialize(line, theproc = nil) { ... } ⇒ void
rubocop:disable Lint/ReturnInVoidContext Initializes a new Watchfor instance.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'documented/common/watchfor.rb', line 14 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 |