class PM::Trigger

A Trigger executes code when it sees a particular array of bytes. Instruments have zero or more triggers.

Since we want to save them to files, we store the text representation as well.

Attributes

bytes[RW]
code_chunk[RW]

Public Class Methods

new(bytes, code_chunk) click to toggle source
# File lib/patchmaster/trigger.rb, line 12
def initialize(bytes, code_chunk)
  @bytes, @code_chunk = bytes, code_chunk
end

Public Instance Methods

method_missing(sym, *args) click to toggle source
# File lib/patchmaster/trigger.rb, line 16
def method_missing(sym, *args)
  PM::PatchMaster.instance.send(sym, *args)
end
signal(bytes) click to toggle source

If bytes matches our +@bytes+ array then run +@code_chunk+.

# File lib/patchmaster/trigger.rb, line 21
def signal(bytes)
  if bytes == @bytes
    pm = PM::PatchMaster.instance
    @code_chunk.run(pm)
    pm.gui.refresh if pm.gui
  end
end
to_s() click to toggle source
# File lib/patchmaster/trigger.rb, line 29
def to_s
  "#{@bytes.inspect} => #{(@code_chunk.text || '# no block text found').gsub(/\n\s*/, '; ')}"
end