Class: WebTools::Support::Debugger::Frame::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/web_tools/support/debugger.rb

Overview

Emulates the context of a frame execution Defines accessors to the frame locals and sets the instance variables to point to the original object’s values

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rcv) ⇒ Context

Returns a new instance of Context.



284
285
286
# File 'lib/web_tools/support/debugger.rb', line 284

def initialize(rcv)
  @receiver = rcv
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



296
297
298
# File 'lib/web_tools/support/debugger.rb', line 296

def method_missing(method, *args, &block)
  @receiver.send(method, *args, &block)
end

Class Method Details

.create_for(frame, receiver, context_hash) ⇒ Object

Tries to create a duplicate of the receiver. If that is not possible, creates a new instance of self. In any case, a singleton class is added to define accessors to frame local values



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/web_tools/support/debugger.rb', line 255

def self.create_for(frame, receiver, context_hash)
  rcv = nil
  begin
    rcv = receiver.dup
  rescue Exception
  end
  if receiver === rcv || rcv.nil?
    rcv = self.new(receiver)

    receiver.instance_variables do |name|
      rcv.instance_variable_set(name, receiver.instance_variable_get(name))
    end

    receiver_mod = (receiver.is_a?(Module) ? receiver : receiver.class)
    receiver_mod.constants do |sym|
      rcv.singleton_class.const_set(sym, receiver_mod.const_get(sym))
    end
  end

  context_hash.each do |k,v|
    next if [:"(self)", :"(class)", :"(receiver)"].include? k
    rcv.singleton_class.define_method(:"#{k}") { v }
    rcv.singleton_class.define_method(:"#{k}=") do |v|
      frame.thread.__frame_at_temp_named_put(frame.index, k, v)
    end
  end
  rcv
end

Instance Method Details

#myselfObject



288
289
290
# File 'lib/web_tools/support/debugger.rb', line 288

def myself
  @receiver
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


292
293
294
# File 'lib/web_tools/support/debugger.rb', line 292

def respond_to?(method)
  @receiver.respond_to? method
end