Module: Truffle::Attachments

Defined in:
truffle/src/main/ruby/core/truffle/attachments.rb

Overview

Attach blocks to specific lines of existing code. Like Kernel#set_trace_func, but for specific lines only, and fast enough to be used for hot-code-path monkey patching if you want.

Defined Under Namespace

Classes: Attachment

Class Method Summary (collapse)

Class Method Details

+ (Attachment) attach(file, line, &block)

Attach a block to be called each time before a given line in a given file is executed, passing the binding at that point to the block.

Examples

attachment = Truffle::Attachments.attach(__FILE__, 21) do |binding|
  # Double the value of local variable foo before this line runs
  binding.local_variable_set(:foo, binding.local_variable_get(:foo) * 2)
end
...
attachment.detach

Returns:



30
31
32
# File 'truffle/src/main/ruby/core/truffle/attachments.rb', line 30

def self.attach(file, line, &block)
  Attachment.new(Truffle::Primitive.attach(file, line, &block))
end