Class: BindingDumper::CoreExt::MagicContextPatchBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/binding_dumper/core_ext/magic_context_patch_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(undumped) ⇒ MagicContextPatchBuilder

Returns a new instance of MagicContextPatchBuilder.



30
31
32
# File 'lib/binding_dumper/core_ext/magic_context_patch_builder.rb', line 30

def initialize(undumped)
  @undumped = undumped
end

Instance Attribute Details

#undumpedObject (readonly)

Returns the value of attribute undumped.



28
29
30
# File 'lib/binding_dumper/core_ext/magic_context_patch_builder.rb', line 28

def undumped
  @undumped
end

Instance Method Details

#patchModule

Returns module that is ready for patching existing context

Returns:

  • (Module)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/binding_dumper/core_ext/magic_context_patch_builder.rb', line 38

def patch
  undumped = self.undumped
  Module.new do
    define_method :_local_binding do
      result = binding

      undumped[:lvars].each do |lvar_name, lvar|
        result.eval("#{lvar_name} = ObjectSpace._id2ref(#{lvar.object_id})")
      end

      mod = LocalBindingPatchBuilder.new(undumped).patch
      result.extend(mod)
    end
  end
end